PowerShell Archive Users Not Logged in 90 Days

email me

$DaysInactive = (Get-Date).AddDays(-90)
$Leavers = Get-ADUser -Filter { Enabled -eq $false -and LastLogonTimeStamp -ge $DaysInactive } -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
}

}