locked
Powershell script to get the list of all users with groups they are member of RRS feed

  • Question

  • Hi

    I need a list of all users in AD together with the groups they are member of. I'm new in powershell and trying to produce the result I need. I've come up with the below script but it didn't show anything on the csv file. Can someone please help me?

    (GET-ADUSER -Filter * –Properties Description | Select-Object MemberOf).MemberOf | Where-Object {$_} | Export-Csv C:\Scripts\allusers5.csv 

    Thursday, August 13, 2015 6:26 AM

Answers

  • Hi WhiteSql,

    As Mekac said, you are passing '-Properties Description' down the pipe and expecting to 'Select MemberOf'

    Any of this should do it.

    get-aduser -filter * -Properties Memberof | select Name,@{n="MemberOf"; e={"$($_.Memberof)"}} | export-csv .\MembrGrp.csv
    
    
    
    get-aduser -filter * | select Name,@{n="MemberOf"; e={"$((Get-ADPrincipalGroupMembership $_).Name)"}} | export-csv .\MembrGrpAD.csv

    This article has several examples:

    How to get all groups that a user is a member of?

    http://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-a-user-is-a-member-of


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Proposed as answer by Elaine Jing Friday, August 14, 2015 8:27 AM
    • Marked as answer by Elaine Jing Tuesday, August 18, 2015 2:38 AM
    Thursday, August 13, 2015 9:23 AM

All replies

  • Dont create a new (duplicate) threads  ... and btw, try to get all required objects before u make pipeline

    U have to specify "memberof" as required property, it isnt received by default.

    • Edited by Mekac Thursday, August 13, 2015 6:43 AM
    Thursday, August 13, 2015 6:41 AM
  • Hi WhiteSql,

    As Mekac said, you are passing '-Properties Description' down the pipe and expecting to 'Select MemberOf'

    Any of this should do it.

    get-aduser -filter * -Properties Memberof | select Name,@{n="MemberOf"; e={"$($_.Memberof)"}} | export-csv .\MembrGrp.csv
    
    
    
    get-aduser -filter * | select Name,@{n="MemberOf"; e={"$((Get-ADPrincipalGroupMembership $_).Name)"}} | export-csv .\MembrGrpAD.csv

    This article has several examples:

    How to get all groups that a user is a member of?

    http://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-a-user-is-a-member-of


    Regards,

    Satyajit

    Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Proposed as answer by Elaine Jing Friday, August 14, 2015 8:27 AM
    • Marked as answer by Elaine Jing Tuesday, August 18, 2015 2:38 AM
    Thursday, August 13, 2015 9:23 AM