Skip OU move for Domain Admin accounts
This commit is contained in:
+8
-3
@@ -186,10 +186,16 @@ foreach ($entry in $Deduped.Values) {
|
|||||||
if ($DryRun) { $disables++ }
|
if ($DryRun) { $disables++ }
|
||||||
}
|
}
|
||||||
|
|
||||||
# Move user to correct OU
|
# Move user to correct OU (skip Domain Admins)
|
||||||
if ($willMove) {
|
if ($willMove) {
|
||||||
if ($DryRun) {
|
$isDomainAdmin = (Get-ADUser $samAccount -Properties MemberOf).MemberOf |
|
||||||
|
Where-Object { $_ -match "^CN=Domain Admins," }
|
||||||
|
|
||||||
|
if ($isDomainAdmin) {
|
||||||
|
Write-Log " OU Move : SKIPPED - user is a Domain Admin" "Yellow"
|
||||||
|
} elseif ($DryRun) {
|
||||||
Write-Log " OU Move : WOULD MOVE to $targetOU" "Magenta"
|
Write-Log " OU Move : WOULD MOVE to $targetOU" "Magenta"
|
||||||
|
$moved++
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Move-ADObject -Identity $adUser.DistinguishedName -TargetPath $targetOU
|
Move-ADObject -Identity $adUser.DistinguishedName -TargetPath $targetOU
|
||||||
@@ -199,7 +205,6 @@ foreach ($entry in $Deduped.Values) {
|
|||||||
Write-Log " OU Move : FAILED to move - $_" "Red"
|
Write-Log " OU Move : FAILED to move - $_" "Red"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($DryRun) { $moved++ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user