PowerShell to return users created in the last 31 days

less than 1 minute read

April 2018

This will return all the users in the users OU that have bee created in the last 31 days:

$createdSinceDate = ((Get-Date).AddDays(-31)).Date
$ou = 'OU=users ,OU=Company,DC=matthewdavis111,DC=com'

Get-ADUser -Filter {whenCreated -ge $createdSinceDate} -Properties whenCreated -SearchBase $ou

Use Sort-Object to sort by created date

Get-ADUser -Filter {whenCreated -ge $createdSinceDate} -Properties whenCreated -SearchBase $ou | Select-Object userprincipalname, whencreated | Sort-Object whencreated

Output to CSV

Get-ADUser -Filter {whenCreated -ge $createdSinceDate} -Properties whenCreated -SearchBase $ou | Select-Object userprincipalname, whencreated | Sort-Object whencreated | Export-Csv C:\temp\skip-created-users.csv -NoTypeInformation