尝试运行该脚本:
Get-ADUser -Filter * -SearchBase "OU=Department,DC=Company,DC=COM" -Properties employeeID,displayName,surname,givenname,physicalDeliveryOfficeName,title,department,company,memberof
当脚本运行时,它会抓取 > 下的所有内容OU=Department
,但我怎样才能让它仅抓取Department
>下的用户对象Users
?
答案1
您只需要使用-SearchScope
参数并传递参数来告诉命令如果您不指定任何参数和值则OneLevel
不要按照其所采用的默认值进行遍历。SubTree
-SearchScope
因此只需包括:Get-ADUser -Filter * -SearchScope OneLevel <Rest of your command>
示例 PowerShell
$SearchBase = "OU=Department,DC=Company,DC=COM"
Get-ADUser -Filter * -SearchScope OneLevel -SearchBase $SearchBase -Properties employeeID,displayName,surname,givenname,physicalDeliveryOfficeName,title,department,company,memberof
更多资源
-
-SearchBase
当搜索库参数设置为空字符串并且您连接到 GC 端口,则将搜索所有分区。
-
-SearchScope The scope of an AD search. Possible values for this parameter are: Base or 0 Search only the current path or object. OneLevel or 1 Search the immediate children Subtree or 2 Search the current path/object and all children
答案2
您可以简单地将另一个 OU 放在父 OU 后面,在您的例子中为“OU=Department,OU=User,DC=Company,DC=COM”
Get-ADUser -Filter * -SearchBase “OU=部门,OU=用户,DC=公司,DC=COM” -属性 employeeID,displayName,surname,givenname,physicalDeliveryOfficeName,title,department,company,memberof