[catlist name=”PowerShell ADSI and Active Directory” conditional_title=”Other Posts in this Series:” numberposts=5 pagination=yes customfield_orderby=”series_post_order” order=”asc”]
This post provides a simple example of how we can use PowerShell ADSI to search users in Active Directory. You may wish to further optimise this by using LDAP filters.
$searcher=[adsisearcher]'(&(objectCategory=person)(objectClass=user))'
$searcher.PageSize = 200
$colProplist = "samaccountname"
foreach ($i in $colPropList) { $searcher.PropertiesToLoad.Add($i) | out-null }
$Users = $searcher.findall()
foreach ($user in $Users) {
write-host ($user.Properties).samaccountname
}

