Operating system: Windows Server 2016
PowerShell version(s): 5.1.14393.3866
Hello,
I'm building a PowerShell Form to detect and connect to our VPN when needed. I have various conditions (checking network interfaces, domain connectivity, etc) and I'm catching errors from rasdial. Everything is working as expected. There is no user interaction. It's jus ta GUI to let the user know what's going on.
On one of the conditions, I have a for loop, that retries the connection 10 times. At the 10th time it outputs that the connection failed and the user should contact the administrator (with an if($i -eq 0)). On all conditions I'm using:
$formtext.Close()
return
But on this case the script just goes to the first line and starts again. I might be doing something wrong with the GUI. I have the form load empty:
- $form_Load = {
- }
- And created my script like:
- $myscript = {
- (...) my code (...)
- foreach($adapter in $netProfile)
- { (...) }
- #if anything was not taken in account, close the form anyway
- #there is no x button or icon on taskbar
- #can be forced to close on Task Manager
- escreverEventLog -eventID 999 -message "Fechar script (form) caso chegue ao final do script sem que nenhuma das condições anteriores o tenha fechado"
- $formAlwaysOnVPNRedeCorp.Close()
- return 0
- }
On the properties, on the right menu, under Load I have the formLoad, and on Active I have myScript. At the end of this event I have the the code above, writing to the event viewer but this part never runs.
As this is automatic, with no buttons, or user interaction, am I doing something wrong regarding the way I should use the form? Just want to stop the script after the foreach and close the form, not running anything elese.
Thank you.