$timespan = New-Timespan -Days 180
Search-ADAccount -UsersOnly -AccountInactive -TimeSpan $timespan | Select-Object UserPrincipalName ,Name | Export-Csv -Path C:\InactiveUser.csv -Encoding UTF8 -NoTypeInformation
$DisableUsers=Import-CSV C:\InactiveUser.csv
ForEach ($User01 in $DisableUsers)
{
Get-ADUser -Identity $User01.Name | foreach {Move-ADObject -Identity $_.ObjectGuid -TargetPath ‘OU=DisableUsers,OU=2024年,OU=离职员工,DC=abc,DC=com’ }
#Disable-ADAccount -Identity $($User01.Name)
#$ObjectGuid01 = (Get-ADUser -Identity $User01| Select-Object ObjectGuid).objectGuid.Guid
#Move-ADObject -Identity $ObjectGuid01 -TargetPath ‘OU=DisableUsers,OU=2024年,OU=离职员工,DC=thtfpc,DC=com’
}