We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Ignore errors in Powershell

NehaReddyH
ServiceNow Employee

Hi,

 

Im running a script which pulls list of AD group members from a remote server. When i run the script for some groups im not able to fetch the members due to some error. I want the script to ignore the error and continue execution for rest other groups. For this i added $ErrorActionPreference= 'silentlycontinue'; to the script. This worked when i ran on the server but it fails from the servicenow instance. Any ideas here?

$groups= @("LISTOFGrouphere");

foreach ($group in $groups){

$ErrorActionPreference= 'silentlycontinue';

Get-ADGroupMember -Identity $group | Select samaccountname | ConvertTo-Json;

}

PS: I also tried Get-ADGroupMember -Identity $group -ErrorAction SilentlyContinue | Select samaccountname | ConvertTo-Json;

Thanks!

0 REPLIES 0