0

I've had trouble closing my powershell script. I've got some forms from PowerGUI and included a function at the beginning of the handler that loads the form.

Simple task: Check a variable. If it's $false, close the program/application.

exit and break throw a Microsoft .Net Error, which can be clicked away when pressing "Continue" and the script continues.

Here are the details of the .net error. http://pastebin.com/phdspwsT

Thank you very much!

3
  • How about posting the script that causes the error too? Commented Feb 3, 2014 at 9:25
  • If ($check_auth) {} Else { Break } Commented Feb 3, 2014 at 10:34
  • So if you create a .ps1 script file that contains just the code above, you'll get the the error as per Pastebin? Commented Feb 3, 2014 at 11:21

1 Answer 1

1

If you need to close the form during the OnLoad event don't use break. Try calling $sender.Close(). Another thing to try is $sender.DialogResult = 'Cancel'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.