Hello,
I am building a script to do some checks (file exists, service exists etc.)
Each check is within its own function.
I made a function (funcExitScript) that all other functions point to on a certain condition, e.g.
function checkthis{
if this ok, ok
elseif this not ok go to funcExitScript
}
Now this works but I cannot stop the script gracefully.
I need the series of functions to stop executing when one of them is having a condition I set and the only thing the user can do is to click on Exit.
Tried using Break and Exit but I get an Unhandled Exception Error (even after setting the global preference to silently continue.
How to stop a script without exception error
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
How to stop a script without exception error
Is this a normal script or a GUI script?
What version of PowerShell are you using?
What error message are you getting?
David
What version of PowerShell are you using?
What error message are you getting?
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- william.mcgregor
- Posts: 2
- Last visit: Mon Aug 25, 2014 7:06 pm
How to stop a script without exception error
I am having the same issue. I am creating a package with a form that runs scripts within the package. The form is actually generated by Powershell Studio 2012 in the form of a .pff file.
Even when I generated a pre configured gui form from scratch in the tool, there was no exit commands associated with the exit button, however it does exit the form.
Help would be fantastic
Will
Even when I generated a pre configured gui form from scratch in the tool, there was no exit commands associated with the exit button, however it does exit the form.
Help would be fantastic
Will
- william.mcgregor
- Posts: 2
- Last visit: Mon Aug 25, 2014 7:06 pm
How to stop a script without exception error
Amendment to the above post.
the command "$form1.Close()" will work where you substitute "$form1" for your form name. in the .pff file, go to the designer view, and then click the outer edge of the form. In the properties "Design - {Name}" is the name of the form. Add the command above to the click event of the button and your application will exit.
the command "$form1.Close()" will work where you substitute "$form1" for your form name. in the .pff file, go to the designer view, and then click the outer edge of the form. In the properties "Design - {Name}" is the name of the form. Add the command above to the click event of the button and your application will exit.
How to stop a script without exception error
Yes the close method will work or you can also use the DialogResult property of the Button. See the Spotlight on the Button Control for more details:
http://www.sapien.com/blog/2011/06/07/p ... n-control/
If you use $form.Close() it will not end the script execution of an event, so be sure to use a "return" afterwards.
if($failed)
{
$form.Close()
return #Otherwise it will continue to execute the event
}
#continue script
...
David
http://www.sapien.com/blog/2011/06/07/p ... n-control/
If you use $form.Close() it will not end the script execution of an event, so be sure to use a "return" afterwards.
if($failed)
{
$form.Close()
return #Otherwise it will continue to execute the event
}
#continue script
...
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.