I am trying to suppress an error in the following statement:
$notes = Get-AdGroup $permissiongroup -Properties info
$notes | Select-Object -expandproperty info -ErrorAction SilentlyContinue
This is to see if there is information in the 'notes' field in AD.
If there is no info, I (logically) get the following error:
Select-Object : Cannot process argument because the value of argument "obj" is null. Change the value of argument "obj" to a non-null value. At line:1 char:10 + $notes | Select-Object -ErrorAction 0 -expandproperty info + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Select-Object], PSArgumentNullException + FullyQualifiedErrorId : ArgumentNull,Microsoft.PowerShell.Commands.SelectObjectCommand
How can I suppress this error? SilentlyContinue does not seem to work in any way?
UPDATE Fixed it with try/catch, thanks.