r/PowerShell•
SlinkyBlack

Find all users created last month?

I am trying to create a script that will pull all users created in the last month. So far I have something pretty manual

$After = first day of the month
$Before = last day of the month

$NewAccounts = Get-ADUser -Filter {whenCreated -ge $After} -Properties whenCreated,EmailAddress | Where-Object whenCreated -le $Before  | Select-Object Name,whenCreated,EmailAddress

It's pretty clunky and manual, I am hoping to streamline it. Does any one know if there is a way to compare only the Month on whenCreated?

Posted Aug 17, 2017, 7:31 PM UTC

37
Loading comments…