none
Export all AD contacts and groups they are members of RRS feed

  • Question

  • Hi,

    Can anyone help me? I want to export all of my AD contacts along with email address and groups they are members of. So basically something like this;

    Name    Email                           Groups

    User1    user1@export.com        Group1, Group2, Group3, Group4

    or like this

    Name

    Group1
    Group2
    Group3
    Group4

    It should be simple but I'm a basic user and i'm finding it hard to put a script together. 

    All I've got is this which lists the contact names;

    Get-ADObject -Server serverdc01 -LDAPFilter "objectclass=contact" | Select-Object -Property name

    Any help is appreciated

    Regards

    Barvo


    Monday, March 5, 2018 1:54 PM

Answers

  • Look in the Gallery for pre-written scripts.

    Get-ADObject  -Filter "objectclass -eq 'contact'" -prop mail,memberof|
         select name, mail, @{n='Groups';e={$_.Memberof -join '|'}} |
    Export-Csv contacts.csv


    \_(ツ)_/



    Monday, March 5, 2018 2:00 PM

All replies

  • Look in the Gallery for pre-written scripts.

    Get-ADObject  -Filter "objectclass -eq 'contact'" -prop mail,memberof|
         select name, mail, @{n='Groups';e={$_.Memberof -join '|'}} |
    Export-Csv contacts.csv


    \_(ツ)_/



    Monday, March 5, 2018 2:00 PM
  • Hi,

    Try this:

    Get-ADUser -Filter * -Properties * | `
        Select -Property Name, `
            @{name="Groups"; expression={ ($_.MemberOf -replace 'CN=(.*?),(.*)','$1') -join ', ' }} | ft

    Best,
    Toby

    Monday, March 5, 2018 2:03 PM
  • Get-AdUser does not return contacts.  It only retrieves user objects.  "FT" cannot export data.

    \_(ツ)_/


    • Edited by jrv Monday, March 5, 2018 2:06 PM
    Monday, March 5, 2018 2:05 PM
  • Sorry, my bad. I've misread the op.
    Monday, March 5, 2018 2:07 PM
  • Sorry, my bad. I've misread the op.

    No prob.  Looked that way.


    \_(ツ)_/

    Monday, March 5, 2018 2:11 PM
  • Thanks JRV and Toby for your prompt response. Much appreciated. Just one thing. The export worked fine but it has listed the group as a canonical name. How can I display the 'friendly' group name?
    Monday, March 5, 2018 2:25 PM
  • Thanks JRV and Toby for your prompt response. Much appreciated. Just one thing. The export worked fine but it has listed the group as a canonical name. How can I display the 'friendly' group name?
    Monday, March 5, 2018 2:25 PM
  • Canonical name? I don't think so.

    Look up "canonical" name to see what that is.

    The group name is the "CN=<name>" of the string. 


    \_(ツ)_/

    Monday, March 5, 2018 2:27 PM
  • Apologies. Canonical is for DNS. 

    I meant the DN. Can I replace the DN for the group name?

    Monday, March 5, 2018 2:37 PM
  • Thanks for your help. Really appreciate it.

    Apologies if it was a simple\stupid question. I'll learn powershell over time and hopefully ask more complex ones!

    Cheers

    Barvo

     
    Monday, March 5, 2018 3:03 PM
  • This does exactly that:

    $_.MemberOf -replace 'CN=(.*?),(.*)','$1'

    Monday, March 5, 2018 3:10 PM
  • Thanks for your help. Really appreciate it.

    Apologies if it was a simple\stupid question. I'll learn powershell over time and hopefully ask more complex ones!

    Cheers

    Barvo

     

    No. It is for AD in this case.  It is a specific attribute on an AD object and is called "canonicalName".


    \_(ツ)_/

    Monday, March 5, 2018 3:12 PM
  • Yes it does. Thanks Toby. Thats awsome. Works a treat. 

    Cheers Everyone. 


    Monday, March 5, 2018 3:42 PM