Get-ADUser -SearchBase

38,672

You only need to use the -SearchScope parameter and pass it the OneLevel argument to tell the command to not traverse per the default SubTree value it takes if you do not specify any -SearchScope parameter and value.

So just include: Get-ADUser -Filter * -SearchScope OneLevel <Rest of your command>

Example 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

Further Resources

  • Get-ADUser -SearchBase

    -SearchBase

    When the value of the SearchBase parameter is set to an empty string and you are connected to a GC port, all partitions will be searched.

    source

  • Get-ADUser

    -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
    

    source

Share:
38,672

Related videos on Youtube

Westfall_T
Author by

Westfall_T

Do not go gentle into that good night, Old age should burn and rave at close of day; Rage, rage against the dying of the light. Though wise men at their end know dark is right, Because their words had forked no lightning they Do not go gentle into that good night.

Updated on September 18, 2022

Comments

  • Westfall_T
    Westfall_T over 1 year

    Trying to run this script:

    Get-ADUser -Filter * -SearchBase "OU=Department,DC=Company,DC=COM" -Properties employeeID,displayName,surname,givenname,physicalDeliveryOfficeName,title,department,company,memberof 
    

    When the script runs it grabs everything under OU=Department but how can I get it to just grab user objects under Department > Users?