none
Export Users to CSV RRS feed

  • Question

  • We have Hundreds of customers, many separated across several companies and OUs.

    What I need is a Power Shell script to export existing user information (User Name, E-mail, Mailbox Size, Number of e-mails, Real Name, Creation Date, etc.) to a CSV sheet, Based on OU, Or Company name, or Domain.

    Is this at all possible?


    I am very new to Windows Power Shell and I have no idea where to start, especially considering of the potential of breaking something critical.

    Thursday, January 3, 2013 6:31 PM

Answers

  • Hi,

    You can use Get-ADUser and Export-Csv cmdlets like below:

    Get-ADUser -Filter * -SearchBase "ou=Ou,dc=contoso,dc=com" -Properties * | Export-Csv  "c:\somefile.csv"

    The parameter "-Filter" is used to specify the query string, "-SearchBase" to specify an Active Directory path to search under and the "-Properties" to specify user's properties you want to export.

    Details please go to:
    http://technet.microsoft.com/en-us/library/ee617241.aspx

    Regards,
    Cicely

    • Proposed as answer by bshwjt Friday, January 4, 2013 6:53 AM
    • Marked as answer by Cicely FengModerator Tuesday, January 8, 2013 2:15 AM
    Friday, January 4, 2013 6:04 AM
    Moderator
  • Cicely suggestion will work out , but it conatins to many information and the some information will not be in user friendly (Eg - Account Expire, Bad Password TIme etc).

    Moreover you can not get the Email counts and size of the email box if you query AD , For that you need to query Exchange Server where the Email accounts exists.

    Can you please let us know what exact information is needed  ? Accordingly we will try to reply

    Too much of information might lead you to confusion :)

    Regards,

    _Prashant_


    MCSA|MCITP SA|Microsoft Exchange 2003 Blog - http://prashant1987.wordpress.com Disclaimer: This posting is provided AS-IS with no warranties/guarantees and confers no rights.


    Friday, January 4, 2013 9:48 AM
  • That is a great point Prasanth. All Exchange related information, you may need to get  it from Exchange server .  For that purpose it better to use Exchange module PowerShell cmdlets.  Here is an example:

    http://technet.microsoft.com/en-us/library/bb124612(v=exchg.141).aspx


    Santhosh Sivarajan | Houston, TX

    Windows 2012 Book - Migrating from 2008 to Windows Server 2012

    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

    This posting is provided AS IS with no warranties,and confers no rights.

    Sunday, January 6, 2013 5:54 PM
    Moderator

All replies

  • You can use Power Shell or any other scripting language.  You can even use DS commands. 

    Here are some examples - http://social.technet.microsoft.com/wiki/contents/articles/3537.active-directory-active-directory-domain-services-ad-ds-commands-and-scripts.aspx

    You can use  the following command to export all samAccountName and Name to an output file.  Modify the filter based on your requirement. 

    Dsquery * -filter "&(objectClass=User)(objectCategory=Person)" –attr samAccountName Name >>Output.csv


    Santhosh Sivarajan | Houston, TX

    Windows 2012 Book - Migrating from 2008 to Windows Server 2012

    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

    This posting is provided AS IS with no warranties,and confers no rights.

    • Proposed as answer by bshwjt Friday, January 4, 2013 6:52 AM
    Thursday, January 3, 2013 7:37 PM
    Moderator
  • Hi,

    You can use Get-ADUser and Export-Csv cmdlets like below:

    Get-ADUser -Filter * -SearchBase "ou=Ou,dc=contoso,dc=com" -Properties * | Export-Csv  "c:\somefile.csv"

    The parameter "-Filter" is used to specify the query string, "-SearchBase" to specify an Active Directory path to search under and the "-Properties" to specify user's properties you want to export.

    Details please go to:
    http://technet.microsoft.com/en-us/library/ee617241.aspx

    Regards,
    Cicely

    • Proposed as answer by bshwjt Friday, January 4, 2013 6:53 AM
    • Marked as answer by Cicely FengModerator Tuesday, January 8, 2013 2:15 AM
    Friday, January 4, 2013 6:04 AM
    Moderator
  • Cicely suggestion will work out , but it conatins to many information and the some information will not be in user friendly (Eg - Account Expire, Bad Password TIme etc).

    Moreover you can not get the Email counts and size of the email box if you query AD , For that you need to query Exchange Server where the Email accounts exists.

    Can you please let us know what exact information is needed  ? Accordingly we will try to reply

    Too much of information might lead you to confusion :)

    Regards,

    _Prashant_


    MCSA|MCITP SA|Microsoft Exchange 2003 Blog - http://prashant1987.wordpress.com Disclaimer: This posting is provided AS-IS with no warranties/guarantees and confers no rights.


    Friday, January 4, 2013 9:48 AM
  • That is a great point Prasanth. All Exchange related information, you may need to get  it from Exchange server .  For that purpose it better to use Exchange module PowerShell cmdlets.  Here is an example:

    http://technet.microsoft.com/en-us/library/bb124612(v=exchg.141).aspx


    Santhosh Sivarajan | Houston, TX

    Windows 2012 Book - Migrating from 2008 to Windows Server 2012

    http://www.sivarajan.com/

    FaceBook Twitter LinkedIn SS Tech Forum

    This posting is provided AS IS with no warranties,and confers no rights.

    Sunday, January 6, 2013 5:54 PM
    Moderator
  • This did the trick for me, as I had 5 mins to get the information for my boss, and he was happy the results, as he was going to go through it and clean out the rubbish :-)
    Monday, February 16, 2015 3:59 PM
  • If you are unfamiliar with PowerShell, I reccomde you to use csvde command line tool. It is very simple, just write the following command in cmd:

    csvde -f c:\csv.csv -r objectClass=person -d "OU=HR,DC=microsoft,DC=com"

    If you insist on using PowerShell, there are two script in this article http://www.danapardaz.net/site/en/blog/item/522-how-to-export-users-from-active-directory-to-csv-file

    The articles explain both CSVDE and Get-ADUser. Simply download the scripts and use them if you don't want to delve into the technical details.


    Sunday, May 14, 2017 7:20 AM