0
votes

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.

2
Which version of Powershell are you using? I seem to recall this is a known bug in version 3.crownedjitter

2 Answers

1
votes

Use powershell try / catch to handle that

0
votes

You could try something like:

$notes | ? {$_.info -ne $null} | Select-Object -expandproperty info