Categories

AD provider–get all users in an OU

One thing I forgot in my last post was using the AD provider that comes with the Microsoft AD cmdlets.

$ou = "OU=England,DC=Manticore,DC=org"
Get-ChildItem -Path AD:\$ou | Format-Table Name, DistinguishedName

Gives the same result

Use

$ou = "OU=England,DC=Manticore,DC=org"
Get-ChildItem -Path AD:\$ou  -recurse | Format-Table Name, DistinguishedName

will search the tree using the given OU as a search root

This code will give all objects – if you just want users

Get-ChildItem -Path AD:\$ou -recurse |
where {$_.objectclass -eq "user"} |
Format-Table Name, DistinguishedName

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>