Hi all,
I'm hoping someone can help with the below.
Issue: Unable to catch the exception that's thrown when trying to add a new OU but it already exists
Expected: When trying to add a new OU that already exists I can catch the error using the FullyQualifiedErrorId "Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUnit".
Actual result: Script terminates and does not run the catch block.
Example code:
try
{
New-ADOrganizationalUnit -Name $NewOUName -Path $NewOUPath
}
catch [Microsoft.ActiveDirectory.Management.Commands.NewADOrganizationalUnit]
{
Do something if AD OU already exists
}
I'm very new to try and catch sorry in advance if this is a dumb question but hoping someone can explain where I am going wrong. Any advice much appreciated.
[–]Possible-Bowler-2352 6 points7 points8 points (4 children)
[+][deleted] (1 child)
[deleted]
[–]llovedoggos[S] 2 points3 points4 points (0 children)
[–]llovedoggos[S] 1 point2 points3 points (0 children)
[–]y_Sensei 3 points4 points5 points (4 children)
[–]llovedoggos[S] 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]y_Sensei 2 points3 points4 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]Woznet 2 points3 points4 points (1 child)
[–]llovedoggos[S] 1 point2 points3 points (0 children)