且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PowerShell检查AD中是否存在组

更新时间:2023-11-25 23:01:46

的成员

如您所述,用户已成功添加到AD,然后只有您遇到错误。因此,您可以使用两种方法来避免该错误。您可以尝试使用

As you stated, the users are successfully added to the AD and then only you are getting the error. So you can avoid the error using two ways. You can try using

Get-ADGroupMember -Identity $groupmember -Recursive | Select -ExpandProperty SAMAccountName | -ErrorAction SilentlyContinue

或者您可以尝试这样

try {
Get-ADComputer -Identity "something"
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
Write-Warning "AD computer object not found"
}
catch {}