Get-ADOrganizationalUnit -SearchBase "ou=大生在線失效,dc=51talk,dc=com" -filter * -SearchScope onelevel | Remove-ADOrganizationalUnit -Credential itaccount -Recursive -Confirm:$false
根據提示輸入密碼便可ide
Import-Module ActiveDirectory $changedate = New-Object System.DateTime(2017,12,31) $today= get-date #半年前 $halfyear= $($today.addmonths(-6)) #1年前 $oneyear= $($today.addmonths(-12)) #2年前 $twoyear= $($today.addmonths(-24)) Get-ADObject -SearchBase "ou=大生在線失效,dc=51talk,dc=com" -Filter {(company -like "*辰帆*") -and (objectclass -eq "user") -and (lastlogon -lt $oneyear)} | Move-ADObject -TargetPath "ou=1年前,ou=電銷離職,ou=大生在線失效,dc=51talk,dc=com"