获取ADUser-SearchBase

获取ADUser-SearchBase

尝试运行该脚本:

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

更多资源

  • 获取ADUser-SearchBase

    -SearchBase

    搜索库参数设置为空字符串并且您连接到 GC 端口,则将搜索所有分区。

    来源

  • 获取AD用户

    -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

相关内容