r/PowerShell • u/Quirky_Mousse1991 • Nov 14 '25
“Member of” export
Hi, I have been asked to provide a list of groups each user in a CSV is a member of, is there any way of doing this in bulk? Or would I have to do it individually? Thanks in advanced
0
Upvotes
1
u/Quirky_Mousse1991 Nov 14 '25
Managed to sort it, just exported the SamAccountName with the display names.. doh! Again thanks for the replies!
5
u/KavyaJune Nov 14 '25
Yes. You can do it using PowerShell. Are you using Active Directory or Microsoft 365?
For Microsoft 365 environment, you can use this PowerShell script: https://o365reports.com/2021/04/15/export-office-365-groups-a-user-is-member-of-using-powershell/
For Active Directory,
https://admindroid.com/how-to-check-user-group-membership-in-active-directory
5
u/jeroen-79 Nov 14 '25
Yes there is.
No, that won't be necessary.
2
u/Dragennd1 Nov 14 '25
You can fetch users from the Graph API using Get-MgUser, from an AD environment with Get-AdUser or you can compile the data in a myriad of other ways.
Ultimately, PowerShell has native support for CSVs with the Import-CSV and Export-CSV cmdlets. I'd read up on those and see what you can put together.
We're happy to help if you run into any issues, but you need to at least try to make a script first. This isn't the place to ask for freebies without putting forth some effort of your own first.
2
u/psdarwin Nov 14 '25 edited Nov 14 '25
For AD: Get-ADGroupMember
https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-adgroupmember
For Entra: Get-MgGroup | Get-MgGroupMember
https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/get-mggroup
https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.groups/get-mggroupmember
1
u/ankokudaishogun Nov 14 '25
Most likely but without an example of the original CSV structure it's impossible to state in a definitive manner.
1
u/Fistofpaper Nov 14 '25
"...group memberships for each user in CSV format."
Omg the wording was so confusing