简单来说,我已经准备好了PS脚本,但我想通过Add-ADGroupMember管理向AD安全组添加1000个名称的结果。问题是ADD-Adgroupmember不返回任何结果。最好的方法是什么?
答案 0 :(得分:0)
您可以将来电包裹在try
/ catch
区块中:
$Group = Get-ADGroup "myGroup"
$Users = "habanagold","habanasilver","mrceo"
foreach($User in $Users){
try {
Add-ADGroupMember -Identity $Group -Members $User -ErrorAction Stop
"$User added to $Group" | Out-File C:\path\to\output.log -Append
} catch {
"Failed to add $User to $Group" | Out-File C:\path\to\output.log -Append
}
}