Move disabled user accounts with a PowerShell

March 7th, 2022 | Tags:

Move disabled user accounts with a PowerShell

# To remove the protection 
Get-ADOrganizationalUnit –Filter “Name –eq ‘Branch Offices’” -Properties ProtectedFromAccidentalDeletion | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $False 

# To move the users 
Search-ADAccount –AccountDisabled –UsersOnly –SearchBase “OU=Branch Offices, DC=Company,DC=LAN”  | Move-ADObject –TargetPath “OU=Disabled Users, DC=Company,DC=LAN”

# To re-apply the protection 
Get-ADOrganizationalUnit –Filter “Name –eq ‘Branch Offices’” -Properties ProtectedFromAccidentalDeletion | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $True

# To remove the protection 
Get-ADOrganizationalUnit –Filter “Name –eq ‘Branch Offices’” -Properties ProtectedFromAccidentalDeletion | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $False 
 
# To move the users 
Search-ADAccount –AccountDisabled –UsersOnly –SearchBase “OU=Branch Offices, DC=Company,DC=LAN”  | Move-ADObject –TargetPath “OU=Disabled Users, DC=Company,DC=LAN”
 
# To re-apply the protection 
Get-ADOrganizationalUnit –Filter “Name –eq ‘Branch Offices’” -Properties ProtectedFromAccidentalDeletion | Set-ADOrganizationalUnit -ProtectedFromAccidentalDeletion $True
No comments yet.