Getting Active Directory User Information

getting active directory user information

Whether starting recon on a new client’s environment or migrating a long-term client’s data to new servers, it sometimes is necessary to know some basic information on the user accounts listed in Active Directory.

Recently, I was installing new servers for a public school, and part of the project included the clean-up of unused login scripts that existed on the domain controllers. Additionally, we wanted to add new home drives to all users, but we didn’t know which already existed or where they were already pointed without painstakingly combing through AD account by account.

Utilizing PowerShell for User Info

Around here, we like to stand on the shoulders of giants, so building on Lindsey’s recent post on AD user counts, I turned to my old friend PowerShell. Running the following script on my client’s domain controller gave me just what I needed. I was able to immediately see all my users, which ones were enabled and which were disabled, their login script, their home drive information and the last time they logged on:

Get-ADUser -filter * -properties * | ft -AutoSize enabled, null, Name, null, scriptpath, null, homedrive, null, homedirectory, null, lastlogondate > C:\ADusers.txt


While it may look a bit daunting at first glance, it is actually quite simple when you break it down:

Get-ADUser -filter * -properties *
  • This part tells PowerShell to grab all user accounts that exist in AD.
| ft -AutoSize
  • Formats output as a table and sets column width automatically based on the amount of information returned.
enabled, null, Name, null, scriptpath, null, homedrive, null, homedirectory, null, lastlogondate
  • Pulls information from each of the listed properties for each account. Null isn’t necessary here, but it does add a handy double bracket between each column. This makes the output easier to read and enables you to use the column as a delimiter if you decide to import the output file into Excel.
> C:\ADusers.txt
  • This pipes the output into a text file at the listed location.

By adding other available fields to the table column list, I can easily tweak the information I get however I want. For example, I can change this to show all locked-out accounts, the last bad password attempt for each account and when the accounts were locked.

Adjusting the PowerShell Window

If you run into issues with columns having their content truncated in those annoying fiena… formats, you can adjust the width of your PowerShell window. Just click the icon in the upper-right corner of your PowerShell window and go to Properties > Layout > Window Size. Adjusting it to a higher number will widen the window and allow the columns to fill out:

adjusting window width in PowerShell

The post Getting Active Directory User Information appeared first on InterWorks.


Leave a Reply

Your email address will not be published. Required fields are marked *