ADScripts/Cleanup-DisabledUsers.ps1
2023-09-14 11:13:58 -06:00

20 lines
690 B
PowerShell

# Script to move Disabled Users to Disabled OU
# Removes from Address book as well
Import-Module ActiveDirectory
if (!($cred)){
$cred = Get-Credential -Message "Please Enter your Domain Admin account" -Title "Domain Admin Prompt"
}
Get-ADUser -SearchBase "OU=MPEUsers,DC=MPE,DC=CA" -filter * | where -Property Enabled -eq $false | Move-ADObject -TargetPath "OU=Users,OU=Disabled Objects,DC=mpe,DC=ca" -Credential $cred
$disabledUsers = Get-ADUser -searchbase "OU=Users,OU=Disabled Objects,DC=mpe,DC=ca" -filter * -Properties msExchHideFromAddressLists
foreach ($user in $disabledUsers) {
$user| Set-ADObject -Replace @{msExchHideFromAddressLists=$true} -Credential $cred
}