Ignore errors in Powershell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2022 06:42 AM
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!
- Labels:
-
flow designer
-
MID Server