Get OU Distinguished Name

An Active Directory Organisational Unit’s Distinguished Name (DN) is required constantly when writing PowerShell scripts that target AD objects, but it’s not something the standard “Active Directory Users and Computers” console surfaces directly on an OU’s properties tab — PowerShell is the quickest way to look it up. The Command Get-ADOrganizationalUnit -Filter 'Name -like "*"' […]

Get Ou Distinguished Name
An Active Directory Organisational Unit’s Distinguished Name (DN) is required constantly when writing PowerShell scripts that target AD objects, but it’s not something the standard “Active Directory Users and Computers” console surfaces directly on an OU’s properties tab — PowerShell is the quickest way to look it up.

The Command

Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Format-Table Name, DistinguishedName -AutoSize
This 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 -AutoSize
The 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 -AutoSize
If 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 Amazon

As an Amazon Associate, TechyGeeksHome earns from qualifying purchases.


Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Andrew Armstrong

Andrew Armstrong is a UK-based IT professional with 26+ years of hands-on experience in Windows, Windows Server, SCCM/ConfigMgr, Active Directory, PowerShell, and enterprise infrastructure.

He founded TechyGeeksHome in 2010 and has published over 1,500 practical guides covering real-world IT problems and solutions. When not solving IT problems,

Andrew develops free Windows utilities including Ultimate Settings Panel, which has been downloaded over 850,000 times.