【问题标题】:Get all users that consist bunch of OU with the same names OU=NEEDOU. From a certain database获取由具有相同名称 OU=NEEDOU 的 OU 组成的所有用户。从某个数据库
【发布时间】:2021-03-19 10:31:58
【问题描述】:

我想知道我写的不正确。我需要获取由 10-20 个 OU 组成的具有相同名称 OU=NEEDOU 的所有用户。来自某个数据库。

Get-ADUser -Filter * -Properties DisplayName -SearchBase "OU=neededOU,OU=Mysearchbase,DC=randomname"| 其中 {$_.distinguishedname -like 'OU=NEEDOU*'}

【问题讨论】:

  • Get-ADUser -Filter "DistinguishedName -like '*OU=NEEDOU*'" -Properties DisplayName
  • @Theo DN 不能这样过滤。
  • @filimonic 啊,我忘了..DistinguishedName 是一个构造属性,并且只允许使用-eq 运算符..

标签: windows powershell


【解决方案1】:
Get-ADUser -Filter * ... | Where-Object { $_.DistinguishedName -like "*,OU=NEEDOU,*" }

您忘记在 -like 操作数中开始 *

或者,您可以先搜索所有需要的 OU,然后从中获取用户

Get-ADOrganizationalUnit -Filter '(Name -eq "NEEDOU")' -SearchBase "..." -SearchScope Subtree | 
    ForEach-Object { Get-ADUser -SearchBase $_.DistinguishedName -Filter * -Properties @('...', '...') }

【讨论】:

    猜你喜欢
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    相关资源
    最近更新 更多