PowerShell脚本跳过了一些用户
我有以下脚本,应该运行 Sailpoint IdentityIQ 中的所有身份,并删除成员资格,但它不会随机影响用户,我们在日志中看到它正确处理一个用户,然后启动下一个用户,但该脚本然后从下一个用户开始,不更新之前的用户。
我们可以添加锁或重试直到完成吗?
这是我们已有的代码。
谢谢你!
$ADgroups = Get-ADPrincipalGroupMembership -Identity $adUser | where {$_.Name -ne "Domain Users"}
if ($ADgroups -ne $null){
try{
Remove-ADPrincipalGroupMembership -Identity $adUser -MemberOf $ADgroups -Confirm:$false
wlog "info" "Removed all assigned AD groups." $mainfn
} catch { }
}
I have the following script that should run through all identities from Sailpoint IdentityIQ, and remove the membership, but it randomly don't affect users, we saw in the logs that it process one user correctly and then the next one starts but the script then start with the next user not updating the one before.
Can we add a lock or retry until it's done?
Here's the code we already have.
Thank you!
$ADgroups = Get-ADPrincipalGroupMembership -Identity $adUser | where {$_.Name -ne "Domain Users"}
if ($ADgroups -ne $null){
try{
Remove-ADPrincipalGroupMembership -Identity $adUser -MemberOf $ADgroups -Confirm:$false
wlog "info" "Removed all assigned AD groups." $mainfn
} catch { }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如已经评论过的,您当前的代码不会输出错误,因为您在
catch
块中没有执行任何操作。另外,通过不指定-ErrorAction Stop
,并非所有错误都会使代码执行 catch 块中的任何内容。尝试
As already commented, your current code does not output errors, because you do nothing in the
catch
block. Also, by not specifying-ErrorAction Stop
, not all errors will make the code execute whatever is in the catch block..Try