SharePoint Online: PowerShell to Get Group Members

Requirement: Get SharePoint Online Group Members using PowerShell.

How to Get Group Members in SharePoint Online?

If you’re a SharePoint administrator, you know that there’s a lot of work involved in managing permissions. Whether on-premise or online, it can be challenging to track who has access to what and when they have rights to the content. Are you looking for a way to get group members of the SharePoint Online site? If so, this blog post shows you how to get group members in SharePoint Online. Let’s get started!

To get users in a group in SharePoint Online, follow these steps:

  1. Go to Site Settings >>  Site Permissions >> Advanced Permissions Settings.
  2. Pick the SharePoint Online group you want to get group members.
  3. And the group page gets you all users in a particular group. get sharepoint online group members powershell

Let’s see the SharePoint Online PowerShell to list group members.

SharePoint Online: PowerShell to Get Group Members

If you want to get a list of group members in SharePoint Online, you can use PowerShell. This will give you a quick and easy way to get the information you need. Using this PowerShell script lets you easily get a list of all the members in a group and get specific details on each member, such as their login ID or title. Whether you need to quickly gather information about your groups or just want an easy way to get members of each group, PowerShell is the way to go.

Here is the SharePoint Online PowerShell to get users in a group:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variables
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$GroupName= "Team Site Members"

Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    
    #Get the Group & Members of the group
    $Group = $Ctx.web.SiteGroups.GetByName($GroupName)
    $Ctx.Load($Group)
    $GroupUsers = $Group.Users
    $Ctx.Load($GroupUsers)
    $Ctx.ExecuteQuery()

    #Iterate through each User of the Group
    ForEach($User in $GroupUsers)
    {
        #get sharepoint online group members powershell
        $User | Select Title, Email
    }
}
Catch {
    write-host -f Red "Error Getting Group Users!" $_.Exception.Message
}

This script gets users in a group.

PowerShell to Get Group members with SharePoint Online Management Shell

We can use the Get-SPOUser cmdlet to get users in a group. Here is the PowerShell to list members of the SharePoint Online group:

#Config Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com/"
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$GroupName= "Team Site Members"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
  
#sharepoint online powershell get group members
Get-SPOUser -Site $SiteURL -Group $GroupName
sharepoint online powershell get group members

SharePoint Online PowerShell to Export Group Members

Here is how to export group members to Excel:

Get-SPOUser -Site $SiteURL -Group $GroupName | Select DisplayName, LoginName | Export-csv -NoTypeInformation -Path "C:\temp\GroupUsers.csv"

If you need to get all groups and users in groups from a site, use: SharePoint Online: Users and Groups Report using PowerShell

PnP PowerShell to Get Group Members

You can also use the Get-PnPGroupMember cmdlet to get members of the group using PnP PowerShell.

#Parameter
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
$GroupName = "Marketing Team Site Members"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#sharepoint online pnp powershell get group members
Get-PnPGroupMember -Identity $GroupName

It’s also possible to export members of a group in SharePoint Online to Excel from the web browser: SharePoint Online: Export Group Members to Excel

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

One thought on “SharePoint Online: PowerShell to Get Group Members

  • I can get a list of sites but most have “Group Owner” next to them in the browser and you have the hassle of having to go into each one to see “Membership” details.

    Using powershell I can get the list of sites with Get-SPOSite
    But half the sites show no “owner” I believe because of the “Group Owner” issue.

    How do you get the “Members” details for each site? I need a list of sites and all their members.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *