Solved

Powershell Script to export AD user to a CSV file?

Posted on 2014-02-05
6
56,731 Views
3 Endorsements
Last Modified: 2015-12-28
Hi Experts,

Our service desk deleted a windows user 3 months ago. Now we need to restore the mailbox and I have no idea which database the mailbox was as the user is gone and we have no logs with AD user info.
I would like to find a powershell script that exports AD user account info like useraccount, exchange database, smtp address etc. Does anyone have one?

Things like:  objectClass,cn,displayName,givenName,initials,sn,mailNickname,title,department,physicalDeliveryOfficeName,streetAddress,postalcode,company,co,l,st,telephoneNumber,facsimileTelephoneNumber,mobile,mail,proxyAddresses,memberOf,msExchHomeServer,homemdb
3
Comment
Question by:osagarana
6 Comments
 
LVL 10

Assisted Solution

by:Pramod Ubhe
Pramod Ubhe earned 125 total points
ID: 39835295
Import-Module ActiveDirectory

Get-ADUser -filter * -properties employeeType,EmployeeID,GivenName,Surname,CN,Title,Manager,Department,Country,City,EmailAddress,LastLogonDate,Created -SearchBase "DC=domainname,DC=com" | select employeeType,EmployeeID,GivenName,Surname,CN,Title,Manager,Department,Country,City,EmailAddress,LastLogonDate,Created | ConvertTo-Csv | Out-File c:\output.csv


You can edit the values that you want.
0
 
LVL 31

Assisted Solution

by:LeeDerbyshire
LeeDerbyshire earned 125 total points
ID: 39835510
if you don't enjoy typing:

Import-Module ActiveDirectory
get-aduser -filter * -properties * | export-csv c:\whatever.txt

although you will probably get many more properties than you need :-)
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 125 total points
ID: 39835915
If you are looking to get AD properties and also Exchange Statistics (database/totyou will not be able to produce this with one command. Use the below commands to get the info you are looking for..

AD Attributes
Get-ADObject -filter 'objectclass -eq "user"' -properties * | select | export-csv -NoTypeInformation "c:\ADUsers.csv"

Open in new window


Exchange Statistics (which will get your other information you require database, mailbox size etc)
Get-Mailbox -Resultsize "Unlimited" | Get-MailboxStatistics | select | export-csv -NoTypeInformation "c:\MailboxStats.csv"

Open in new window


Will.
0
 
LVL 2

Assisted Solution

by:allen_rich
allen_rich earned 125 total points
ID: 39838365
The script is given below:

Get-QADUser -SizeLimit 0 `| select-Object SamAccountName,displayname,description `| Export-Csv "c:\folder\export.csv"

or

Get-ADUser -LDAPFilter "(&(!(sAMAccountName=EUR*))(!userAccountControl:1.2.840.113556.1.4.803:=2))" `
    -Properties sAMAccountName, givenName, sn, enabled | Select sAMAccountName, givenName, sn, enabled | `
    Export-Csv -Path c:\Scripts\Users.csv

Please also refer to the given below article to know more about command: get-asuser

http://technet.microsoft.com/en-us/library/ee617241.aspx
0
 
LVL 1

Author Closing Comment

by:osagarana
ID: 39838636
You guys are experts!  :-)
0
 
LVL 1

Expert Comment

by:SquigglyMonkey
ID: 41387522
CSVDE is another method to export all the AD info to a CSV file.
https://technet.microsoft.com/en-us/library/cc732101.aspx
0

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now