我正在寻找一种方法来检索所有没有在Active Directory中分配给他们的经理的用户。无论我尝试,它总是吐出的错误。
工作正常:
Get-ADUser -Filter {-not(lastLogonTimeStamp -like "*")} -Properties * -SearchBase "xxx"
不工作:
Get-ADUser -Filter {-not(manager -like "*")} -Properties * -SearchBase "xxx"
Get-ADUser -Filter {manager -ne "*"} -Properties * -SearchBase "xxx
Get-ADUser -Filter {manager -eq $null} -Properties * -SearchBase "xxx
Get-ADUser -Filter {manager -notlike '*'} -Properties * -SearchBase "xxx
如果不使用where
clause,没有人有正确的语法的想法?
解决方法:
Get-ADUser -SearchBase "xxx" -Filter * -Properties * | where {$_.manager -eq $null}
谢谢您的帮助球员。
使用-LDAPFilter
开关:
Get-ADUser -LDAPFilter "(!manager=*)" -Properties *
我测试此代码,如果除了你需要获得才会启用帐户丢失经理现场,并用1000的用户群体进行测试。如果你想加快搜索,但没有必要的,如果你有时间,可以使用searchbase。 :)
$results =Get-ADUser -Filter * -Properties * -ResultSetSize 1000 | where {$_.manager -eq $null -and $_.enabled -eq $True} |select samaccountname, mail, manager, enabled
$results