简体   繁体   中英

PowerShell Get-ADUser Filter manager empty

I'm looking for a way to retrieve all the users that have no manager assigned to them in the active directory. Whatever I try, it always spits out errors.

Works fine:

Get-ADUser -Filter {-not(lastLogonTimeStamp -like "*")} -Properties * -SearchBase "xxx"     

Doesn't work:

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

Without using the where clause, does anyone have an idea about the correct syntax?

Workaround:

Get-ADUser -SearchBase "xxx" -Filter * -Properties * | where {$_.manager -eq $null}

Thank you for your help guys.

使用-LDAPFilter开关:

Get-ADUser -LDAPFilter "(!manager=*)" -Properties *

I tested this code, if in addition you need to get only enabled accounts missing the manager field and test it with a 1000 user population. You use the searchbase if you want to speed up the search but not necessary if you have time. :)

$results =Get-ADUser -Filter * -Properties * -ResultSetSize 1000 | where {$_.manager -eq $null -and $_.enabled -eq $True} |select samaccountname, mail, manager, enabled
$results

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM