The Command
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Format-Table Name, DistinguishedName -AutoSizeThis requires the Active Directory module for PowerShell (part of RSAT) to be installed and imported. Left as a bare wildcard (
*), this returns every OU in the domain alongside its full Distinguished Name.
Finding One Specific OU
Replace the wildcard with the OU’s name (or a partial match) to narrow the results:Get-ADOrganizationalUnit -Filter 'Name -like "*Sales*"' | Format-Table Name, DistinguishedName -AutoSizeThe resulting
DistinguishedName column gives you the exact string (e.g. OU=Sales,OU=UK,DC=contoso,DC=com) to paste directly into any script or query that needs to target that OU.
Scoping the Search to a Specific Part of the Tree
On a large domain, running the bare command against every OU can return a long list that’s awkward to scroll through. Use-SearchBase to restrict the query to a specific starting point instead of the whole domain, which also speeds up the lookup on big directories:
Get-ADOrganizationalUnit -Filter 'Name -like "*Sales*"' -SearchBase "OU=UK,DC=contoso,DC=com" | Format-Table Name, DistinguishedName -AutoSizeIf you only need the DN and nothing else, drop the pipeline entirely and pull the property straight from the object rather than formatting a table — useful when you’re feeding the value into another command:
(Get-ADOrganizationalUnit -Filter 'Name -eq "Sales"').DistinguishedName
A No-RSAT Alternative: ADSI
If the Active Directory PowerShell module isn’t installed and you can’t add RSAT (e.g. on a locked-down workstation), the older[adsisearcher] type accelerator ships with PowerShell by default and doesn’t need any extra module:
([adsisearcher]"(&(objectCategory=organizationalUnit)(name=Sales))").FindOne().Properties['distinguishedname']It’s clunkier syntax, but it’s a useful fallback to know about when the AD module genuinely isn’t available and you can’t install it there and then.
Gear We Recommend
A few general tech accessories worth having alongside this.
Browse our General Tech Accessories picks on AmazonAs an Amazon Associate, TechyGeeksHome earns from qualifying purchases.
Discover more from TechyGeeksHome
Subscribe to get the latest posts sent to your email.