Link to home
Start Free TrialLog in
Avatar of Jody Davis
Jody DavisFlag for United States of America

asked on

Need an export of Active Directory users created before a certain date

I need a script/command to export a list of currently enabled AD users that were created before June 2015 on our network. This info can be seen from the AD User Object tab in the category - Created:

I'm not sure if this is possible. Please assist if you can. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of FOX
FOX
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$date = Get-Date "6/1/2015"
Get-ADUser -Filter {whenCreated -lt $date -and Enabled -eq $true} -Properties whenCreated | Select samaccountName,whenCreated | sort whencreated | Export-CSV report.csv -notype

Open in new window

@Fox:  Very nice code.  I was just about to add my code when I refreshed and saw yours.  I didn't include the Display Name or the Enabled but did include the Office.

Get-ADUser -Filter * -properties SamAccountname,office,whencreated | ? { $_.whenCreated -le (get-date "June 1, 2015")}|Select Samaccountname,whenCreated,office

And then I see footech's.   also very interesting/nice.
Avatar of Jody Davis

ASKER

These are all great. I took the first one and ran with it, so i'll go with the first - HOWEVER - make sure to remove the ' after the csv at the end of the script. It will of course fail otherwise. Thanks guys!
I went with the first and after removing the ' it worked great. thanks guys!
Jody- Pardon me.  I missed the quote before the c- it should have read:
 Export-Csv 'c:\temp\results.csv' -notypeinformation