Solved

Powershell Script to export AD user to a CSV file?

Posted on 2014-02-05
6
58,797 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video discusses moving either the default database or any database to a new volume.

840 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