Other Posts in this Series:
- LDAP Does Not Return All Active Directory Group Members
- The Difference Between PowerShell ADSI and ADSISearcher
- Use ADSI to Check if a User is a Member of an AD Group
- Use ADSI to Check if a Computer is a Member of an AD Group
- Use PowerShell ADSI to Migrate AD Group Members
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
}
![Use ADSI to Search Users in Active Directory](https://www.alkanesolutions.co.uk/wp-content/uploads/2023/12/use-adsi-to-search-users-in-active-directory-300x169.png)
![Use PowerShell ADSI to Search Users in Active Directory](https://www.alkanesolutions.co.uk/wp-content/themes/twentyeleven-child/images/application-packaging-services-blog.png)