Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
if ($doesUserExist)
{
$distName = (Get-ADUser -Filter { UserPrincipalName -eq $upn } -Server MYSERVER).DistinguishedName
[System.Windows.Forms.MessageBox]::Show("User already exists in Active Directory. `n$distName", "User Exists", 'OK', 'Error')
$formUserCreationAndDepro.Close()
}
If the script finds that a user exists I want to display that message and then stop execution of the script. Apparently .Close() does not close the form or stop execution.
How do I completely stop script execution and close the form?
I don't care what it does I just need it to stop executing if the condition is true and .Close() does not do this.
And thanks but that link isn't particularly helpful to me. I asked a specific question and you gave a very general answer.
"Close" will not terminate an event in progress. YOu will have to return from teh event after posting the close message or code after the Close method will continue to execute.
Abruptly exiting an event after posting a close message may cause a deadlock or an exception which is dependent on the code you are executing.
In th ecaase of the code you posted the form should close with no issues. There is no need to do anything else.
This topic is 2 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.