批量過濾刪除AD中的對象


Get-ADOrganizationalUnit -SearchBase "ou=大生在線失效,dc=51talk,dc=com" -filter *  -SearchScope onelevel | Remove-ADOrganizationalUnit  -Credential  itaccount -Recursive  -Confirm:$false

根據提示輸入密碼便可ide

  1. 過濾特定時間離職的人員
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"
相關文章
相關標籤/搜索