Active Directory + PowerShell: Get users created in the past 7 days

Just a quick one-liner that I had to use today. Gets all AD Users created in the past 7 days:

Get-ADUser -Filter "created -gt '$((Get-Date).AddDays(-7).ToShortDateString())'"

I had to tack on the .ToShortDateString() method, as the filter doesn’t like the long-formatted date and brings back all sorts of accounts, not just those from the past 7 days.

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s