Using Powershell to get a list of user IDs from AD

One of my network admin friends needed an easy way to provide some users with a list of names vs AD account names.

In many organizations, this is easy to guess, for example if my name is  Jack Basement, my id might be jbasement, but in this case, it wasn’t that easy so we needed to go to AD.

There are AD cmdlets, but they are not in powershell by default.

If you have the Remote Server Administration Tools for Windows 7 installed, then you’ll find a link to “Active Directory Module for Windows PowerShell” in your administrator tools menu.

 

Using that we can easily get a list of the users needed and select just the columns we want

for example

We can combine that with the select statement such as this:

Which gives us a nice list

and

which will out put it as a comma separated CSV (Perfect for importing into Excel)

and

which outputs the same thing, but to a file.

 

Now one neat trick, is that often you want to output all the users of a group in AD (technically this is called an Organizational Unit, or OU)

There is an LDAP filter type we can use for this

Whats cool here is that LDAP filters are sometimes a pain to get “just right” so we can cheat:

We can use the distinguished name of a known user in that group and grab the group from that

so for example

results in a bunch of output, the first field is the distingished name and we can copy and paste that for our next command

this outputs all the users in that OU

again we can chain for flexibility

 

Lastly don’t forget get-help

shows a few good examples.
 

One thought on “Using Powershell to get a list of user IDs from AD

Leave a Reply