Share via

Extract users and groups using Powershell

Anonymous
2023-09-05T15:10:09+00:00

I've extracted all of my users and their groups into a CVS file, so I know how to approach this. The command Get-ADGroupMember is the one for that, but even after reading various articles about it like Get-ADGroupMember (ActiveDirectory) | Microsoft Learn, I can't retrieve the information.

Microsoft 365 and Office | Subscription, account, billing | For business | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2023-09-05T16:40:32+00:00

    Dear Lorenzo J225,

    Good day! Thank you for posting to Microsoft Community. We are happy to help you.

    Based on your description, I understand that you have a query "Extract users and groups using PowerShell". 

    Could you please explain clearly so we may further help you? Are you referring to extracting Office 365 users and groups using PowerShell? if so, have you tried using the following command:

    $Group = Get-AzureADGroup -SearchString "<GroupName>"

    Get-AzureADGroupMember -ObjectId $Group.ObjectId -All $true | Select DisplayName, UserPrincipalName |

    Export-CSV "C:\GroupMembers.csv" -NoTypeInformation -Encoding UTF8

    The command you provided, and the article seems to work only in the Active directory, which is outside our support boundary, however I have done some research; I found this script that can help you accomplish this work.

    Get-ADGroup -Filter * | ForEach-Object {Get-ADGroupMember $_ | Select @{Name="GroupName";Expression={$_.Name}},@{Name="UserName";Expression={$_.SamAccountName}}} | Export-Csv -Path "C:\UsersAndGroups.csv" -NoTypeInformation

    This command will retrieve all the groups in your Active Directory and then for each group, it will retrieve the members and select the group name and member name. Finally, it will export the data to a CSV file located at "C:\UsersAndGroups.csv".

    Make sure you have the Active Directory module installed on your computer before running this command. You can install it by running the following command: Install-WindowsFeature RSAT-AD-PowerShell. Please refer to Getting users and group - Microsoft Community Hub.

    If the issue persists; Since the issue is related to On-prem and the issue with Active directory and we here are mainly dedicated to the Online environment, to provide better assistance, we'd like to suggest you post your concern in Microsoft Q&A forum. There would be the engineers have rich experience on on-prem to further help you.

    We do appreciate for your understanding and patience.

    Regards,

    De Paul | Microsoft Community Moderator

    3 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful