Solved

Powershell Script to export AD user to a CSV file?

Posted on 2014-02-05
6
59,382 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video discusses moving either the default database or any database to a new volume.

685 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