PowerShell Archiving Disabled Users Home Directories

email me

$Leavers = Get-ADUser -Filter { Enabled -eq $false } -SearchBase “OU=Employees,DC=DomainName,DC=com” -Properties HomeDirectory

ForEach ($User in $Leavers) {

$ArchivePath = [io.path]::Combine(“Z:\EmployeesArchived”, $User.SamAccountName)

If (Test-Path $User.HomeDirectory) {
Move-Item –Path $User.HomeDirectory -Destination $ArchivePath -Force
}

}