Get-ADOrganizationalUnit -SearchBase "ou=大生在线失效,dc=51talk,dc=com" -filter * -SearchScope onelevel | Remove-ADOrganizationalUnit -Credential itaccount -Recursive -Confirm:$false
根据提示输入密码即可
- 过滤特定时间离职的人员
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"