List users in an OU

Just for completeness this is the code to list the users in an OU. It forms the basis of any bulk modification activity that is based on OU membership

$ou = "OU=BlogTests,DC=Manticore,DC=org"            
Get-ADUser -ResultSetSize 3000 -SearchBase $ou -Filter * |             
Format-Table Name, DistinguishedName            
"`nAD provider"            
Get-ChildItem -Path AD:\$ou  |             
where {$_.objectclass -eq "user"} |             
Format-Table Name, DistinguishedName            
Get-QADUser -SizeLimit 3000 -SearchRoot $ou |             
Format-Table Name, DN            
$root = [ADSI]"LDAP://$ou"            
$search = [adsisearcher]$root            
$search.Filter = "(&(objectclass=user)(objectcategory=user))"            
$search.SizeLimit = 3000            
$results = $search.FindAll()            
foreach ($result in $results){            
    $result.Properties |             
    select @{N="Name"; E={$}}, @{N="DistinguishedName"; E={$_.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>