Get-Aduser -Searchbase

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?

0

1 Answer

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

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.