【问题标题】:PowerShell Get-ADUser Filter manager emptyPowerShell Get-ADUser 过滤器管理器为空
【发布时间】:2014-08-04 10:57:03
【问题描述】:

我正在寻找一种方法来检索所有在活动目录中没有分配管理员的用户。无论我尝试什么,它总是会吐出错误。

工作正常:

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


    【解决方案1】:

    使用-LDAPFilter开关:

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

    【讨论】:

    • 太棒了!在执行 Measure-Command 时,它似乎也比使用 where 子句快 3 倍。谢谢 Raf :)
    • 从源头过滤总是快得多。 Raf 的解决方案从一开始就返回一个具有空管理器字段的用户数组,使用 Where-Object 意味着它需要首先检索每个用户,然后循环遍历它们以确定哪些具有空的管理器字段。
    【解决方案2】:

    我测试了此代码,如果您需要仅启用缺少经理字段的帐户并使用 1000 个用户群对其进行测试。如果您想加快搜索速度,您可以使用搜索库,但如果您有时间,则没有必要。 :)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 2023-02-10
      相关资源
      最近更新 更多