Link to home
Start Free TrialLog in
Avatar of Twhite0909
Twhite0909

asked on

Create AD Query for User name and User Creation Date

I am looking for an AD Query to List all Users and their creation dates.  I need to export this to a CSV file to make a spreadsheet.
Avatar of coraxal
coraxal
Flag of United States of America image

If you dont mind using Quest Powershell, then you can do something like this:

http://www.quest.com/powershell/activeroles-server.aspx

Get-QADUser -SearchRoot "dc=mydomain,dc=com" `
	-DontUseDefaultIncludedProperties `
	-IncludedProperties DN,SamAccountName,Name,whenCreated `
	-SizeLimit 0 | 
	Select-Object SamAccountName,whenCreated |
	Export-Csv C:\myscripts\ADusers.csv -NoTypeInformation

Open in new window

Avatar of Twhite0909
Twhite0909

ASKER

So are we saying there is not an AD query to run and only PowerShell can achieve what Im looking for>?
No, I'm not saying that at all...Powershell is only one way to get you there...I'm sure there are other tools perhaps built-in ones. I only offered Powershell as a possible solution since that's what I'm familiar with. Maybe others can suggest other alternatives
Im not that good with Powershell.  On my DC there is a Active Directory Module for Powershell. I launched that.  My domain is called AD.LOCAL so is this the right command:


Get-ADUser -SearchRoot "dc=ad,dc=local" `
      -DontUseDefaultIncludedProperties `
      -IncludedProperties DN,SamAccountName,Name,whenCreated `
      -SizeLimit 0 |
      Select-Object SamAccountName,whenCreated |
      Export-Csv C:\myscripts\ADusers.csv -NoTypeInformation
Try this

Get-ADUser -Properties * -SearchBase "DC=mydomain,DC=com" | 
        Select-Object SamAccountName,whenCreated |             
        Export-Csv "C:\myscripts\ADusers.csv" -NoTypeInformation

Open in new window

That command asks for an entry for Filter.  I hit Admin and it erroed:

PS C:\Users\WhiteT> Get-ADUser -SearchRoot "dc=ad,dc=local" `
>>       -DontUseDefaultIncludedProperties `
>>       -IncludedProperties DN,SamAccountName,Name,whenCreated `
>>       -SizeLimit 0 |
>>       Select-Object SamAccountName,whenCreated |
>>       Export-Csv C:\myscripts\ADusers.csv -NoTypeInformation
>>
Get-ADUser : A parameter cannot be found that matches parameter name 'SearchRoo
t'.
At line:1 char:23
+ Get-ADUser -SearchRoot <<<<  "dc=ad,dc=local" `
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBind
   ingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory
   .Management.Commands.GetADUser

PS C:\Users\WhiteT>       Export-Csv C:\myscripts\ADusers.csv -NoTypeInformation


cmdlet Export-Csv at command pipeline position 1
Supply values for the following parameters:
InputObject: admin
Export-Csv : Could not find a part of the path 'C:\myscripts\ADusers.csv'.
At line:1 char:17
+       Export-Csv <<<<  C:\myscripts\ADusers.csv -NoTypeInformation
    + CategoryInfo          : OpenError: (:) [Export-Csv], DirectoryNotFoundEx
   ception
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.Ex
   portCsvCommand

PS C:\Users\WhiteT>
ASKER CERTIFIED SOLUTION
Avatar of coraxal
coraxal
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
PERFECT!!  That worked beautifully Thank you SO much!