您好,登錄后才能下訂單哦!
1.特定組中移除禁用賬號
$group= "testgroup"
$members = Get-ADGroupMember -Identity $group
foreach ($memeber in $members){
$user= Get-ADUser -Identity $memeber
if($user.Enabled -eq $false){
Remove-ADGroupMember $group $user -Confirm:$false
}
}
所有組中刪除禁用用戶
$grouplist = Get-ADGroup -SearchBase "OU=test,dc=test,dc=com" -Filter 'GroupCategory -eq "Distribution"' -SearchScope OneLevel
foreach ($group in $grouplist){
$members = Get-ADGroupMember -Identity $group
foreach ($member in $members){
$user = Get-ADUser -Identity $member
if($user.Enabled -eq $false){
Remove-ADGroupMember -Identity $group -Members $user -Confirm:$false
}
}
}
腳本2:
$users = Get-ADUser -Filter {enabled -eq "false"} -SearchBase "ou=test,dc=test,dc=com"
foreach ($user in $users ) {
Get-ADPrincipalGroupMembership -Identity $user | ?{$_.name -ne "domain users"} | %{Remove-ADPrincipalGroupMembership -Identity $user -MemberOf $_ -Confirm:$false}
}
經測試,順利刪除已禁用賬號。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。