Error Catching.
-
Thursday, June 14, 2012 4:06 PM
I'm trying to pull in the local security policy on my servers and I'm running my script against all my servers. For the most part all is fine but on some servers I get the following error message. Can someone tell me what it means and is possible how to fix it? All my information still pulls in so if I could just silentlycontinue on this error it would be great
New-Object : Exception calling ".ctor" with "1" argument(s): "Value was invalid.
Parameter name: sddlForm"
At C:\myscript.ps1:784 char:15
+ $sid = new-object System.Security.Principal.SecurityIdentifier($str)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommandSMaximus7
All Replies
-
Thursday, June 14, 2012 4:24 PM
You can add the erroraction preference with your New-Object call.
New-Object ... -ea silentlycontinue
Grant Ward, a.k.a. Bigteddy
-
Thursday, June 14, 2012 5:46 PMI tried that but still get the error
SMaximus7
-
Thursday, June 14, 2012 6:36 PM
use a try/catchyou wouldn’t want to just pass over the failure of creating an object(normally) because you'd try to use it after and it would crap out.. so do atry catch and do something with it..
Justin Rich
http://jrich523.wordpress.com
PowerShell V3 Guide (Technet)
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by SMaximus7 Thursday, June 14, 2012 7:43 PM
-
Thursday, June 14, 2012 7:43 PMThe try/catch method worked flawlessly. Thanks
SMaximus7
-
Thursday, June 14, 2012 7:51 PM
Hi,
In your case you get terminating error then need use try/catch like Justin said or set trap:
trap [Exception] { write-host "Catched error: $_.Exception.Message" continue } $sid = new-object System.Security.Principal.SecurityIdentifier($str) try { $sid = new-object System.Security.Principal.SecurityIdentifier($str) } catch { write-host "Catched error: $_.Exception.Message" }- Edited by MichalGajdaMVP Thursday, June 14, 2012 7:52 PM
- Edited by MichalGajdaMVP Thursday, June 14, 2012 7:53 PM

