Searching Active Directory for usernames containing something using PowerShell

The Active Directory Users and Computers search / find function doesn’t allow you to search for partial user names.

For example in a school AD setup I wanted to find my test user but I’d forgotten which year I had put them in or what the beginning of the username was. The mmc would just fail to find anything. However “Active Directory Module for Windows PowerShell” can do it using the following command.

PS N:\> Get-ADUser -Filter {SAMAccountName -like "*tuser*"}


DistinguishedName : CN=13TUser,OU=Intake2013,OU=Students,DC=school,DC=internal
Enabled           : True
GivenName         :
Name              : 13TUser
ObjectClass       : user
ObjectGUID        : 5f5d3aa3-9abd-4d38-9433-e035c570d30d
SamAccountName    : 13TUser
SID               : S-1-5-21-1322339111-3138716444-1658823465-1729
Surname           :
UserPrincipalName :

Neat.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Searching Active Directory for usernames containing something using PowerShell

Comment on this topic

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s