Trying to use native powershell way to assign null value to variable which can not be resolved. My understanding if I set Set-StrictMode -Off
I shall be able to do something like below but it fails. Is there a way to tell powershell engine that in case exception is thrown just assign $null
to result and don't show any exceptions without if
statement
PS C:\Users\a> $item = $string.NonExistentmember.Split("/")
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $item = $string.NonExistentmember.Split("/")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull