Powershell Script to Filter AD Accounts and List Attributes

I'm looking for a Powershell script that will list all active users in AD, and also list certain attributes such as name, username, title, and account creation date. This is my first attempt at Powershell, and I've found two scripts that are close to what I'm looking for, but I need a way to combine them.

get-aduser -filter {enabled -eq $true} -Properties whenCreated, title

This script seems to output all of the info I need in a list.

get-aduser -filter {enabled -eq $true} | select name, samaccountname, creationdate, title

This script outputs to a nice table, but the creationdate column is blank.

Does anyone know how write this script so that it's formatted like the table in the second example, but contains all the info I need?

By the way, I'm running Windows Server 2008 R2.
Who is Participating?
x-menConnect With a Mentor IT super heroCommented:
get-aduser -filter {enabled -eq $true} | ft -Properties name, samaccountname, creationdate, title -autosize
Brad212Author Commented:
Thanks x-men. That looks promising, but when I run it I get:
Format-Table : A parameter cannot be found that matches parameter name 'Properties'.

Any ideas?
x-menIT super heroCommented:

sorry, was thinking in english, not in PS...
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Brad212Author Commented:
That helped. I was able to run the script successfully, but my creationdate column is still blank. When I run script #1 from my post, I get real dates returned for whencreated. But when I run your script, I get blanks for creationdate. I tried substituting whencreated for creationdate in your script, but the column is still blank.

I tried an experiment. I took out creationdate and put in 'duck' without quotes. The script generated a table with a column called duck which was all blanks. I'm pretty sure there isn't an AD attribute called duck, so it appears that the script will generate a column for any word, whether its an attribute or not.

Is there another term I should be using instead of creationdate?
x-menIT super heroCommented:
get-aduser | get-member

for a list of attributes
Brad212Author Commented:
It seems like the attribute is WhenCreated, but neither that nor CreationDate returns any results in my table. Its strange that it works in my first script but not the second. I decided to use an AD tool called AD Info Free to run a query and export the results to CSV file. Thanks for your help, X-men.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.