PowerShell中获取-ADUser便有过滤器管理空

问题描述 投票:0回答:2

我正在寻找一种方法来检索所有没有在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

如果不使用whereclause,没有人有正确的语法的想法?

解决方法:

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

谢谢您的帮助球员。

powershell syntax active-directory
2个回答
6
投票

使用-LDAPFilter开关:

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

0
投票

我测试此代码,如果除了你需要获得才会启用帐户丢失经理现场,并用1000的用户群体进行测试。如果你想加快搜索,但没有必要的,如果你有时间,可以使用searchbase。 :)

$results =Get-ADUser -Filter * -Properties * -ResultSetSize 1000 | where {$_.manager -eq $null -and $_.enabled -eq $True} |select samaccountname, mail, manager, enabled
$results
© www.soinside.com 2019 - 2024. All rights reserved.