Page 1 of 1

need help

Posted: Fri Aug 05, 2022 12:26 am
by TheMooxi
Hello,
I need to put a msgbox indicating if the command below was executed successfully or not

$buttonGrant_Click={
#$GroupTest = $textboxCheckGroup.Text
$textboxResultado.Lines = Add-ADGroupMember -Identity $textboxGroup.Text -Members $textboxLogin.Text
}

Example:
If the command execute successfully shows the msg in the popup: 'Access Released'
If the user already has group access, show the msg in the popup: 'User already has group access'
If the command does not execute successfully, displays the msg in the popup: 'Command not executed, check data entered'

Can you help me?

Re: need help

Posted: Fri Aug 05, 2022 1:41 am
by jvierra
If the command doesn't execute correctly, it will throw an exception. You will have to catch the exception and decide which message you want to display.

Start by reviewing the documentation on exception handling in PowerShell. Also review the AD command for how it generates exceptions.

Start with help:
help about_try_catch_finally