How to Get SharePoint Site Members Using PowerShell?

When using PowerShell, I needed to retrieve all the SharePoint site members or specified group members using PowerShell.

In this article, I will show you how to get SharePoint site members using PowerShell with examples using two different approaches. Such as:

  1. Get SharePoint site members from SharePoint Online Management Shell.
  2. Get SharePoint site members from PnP PowerShell.

Use an editor like Visual Studio Code or Windows PowerShell ISE to execute the PowerShell commands.

NOTE:

Only SharePoint site administrators or those with admin access to Microsoft 365(Global administrators) can access the SharePoint site members.

How to Get SharePoint Site Members Using PowerShell [SharePoint Online Management Shell]

In SharePoint Online Management Shell, the Get-SPOUser command is used to get all the SharePoint site members or specific group members.

You should pass the mandatory parameter, such as site URL, to retrieve SharePoint site members.

Syntax:

Get-SPOUser
   -Site <SpoSitePipeBind>
   [-Group <String>]
   [-Limit <String>]
   [-LoginName <String>]

Where;

  • Site: It specifies the SharePoint site URL.
  • Group: It specifies the group name present in the SharePoint site.
  • Limit: It specifies the maximum number of users. By default, it returns the 500 users. If you want to get all the users, provide the value “All.”
  • LoginName: It specifies the SharePoint site user name.

Example 1: Get all the SharePoint Team site members using SharePoint Online Management Shell

This PowerShell command will provide a list of site members present in the specified SharePoint team site.

Get-SPOUser -Site "https://szg52.sharepoint.com/sites/SalesDepartmentTeam"

Execute the above command by clicking the RUN button. The output will appear in the console after execution, as shown in the screenshot below.

how to get sharepoint site members using powershell

You will get a list of all the SharePoint team site members in the console. This list contains the user names, emails, and user belonging groups. It will display all the default users and custom users.

Example 2: Get Specific SharePoint site group members using SharePoint Online Management Shell

This example command will display the specific group(Planning Team Members) members present on the SharePoint site(Sales Department).

Get-SPOUser -Site "https://szg52.sharepoint.com/sites/SalesDepartmentTeam" -Group "Planning Team Members"

Click the RUN button to execute the above command. The output will be displayed in the console after execution, as shown in the screenshot below.

get sharepoint site members using powershell

Here, you will get all provided group members with their names, login names, and connected groups.

Example 3: Get limited SharePoint site members using SharePoint Online Management Shell

Follow the PowerShell command to get limited SharePoint site members.

Get-SPOUser -Site "https://szg52.sharepoint.com/sites/SalesDepartmentTeam" -Limit "10" 

Execute the above command. You will get exactly the specified limited members in the console.

get sharepoint site members using sharepoint online management shell

To get all the site members, set the Limit parameter value to “All.”

Example 4: Get specific SharePoint site member using SharePoint Online Management Shell

Use this PowerShell command to get specific site member details or check whether a member exists on a given site.

Get-SPOUser -Site "https://szg52.sharepoint.com/sites/SalesDepartmentTeam" -LoginName PattiF@szg52.onmicrosoft.com 

Execute the above command by clicking the RUN button. Then, you will see the specified site member details in the console.

how to get a sharepoint site members using powershell

Example 5: Get SharePoint communication site members using SharePoint Online Management Shell

In the same way, to get all the SharePoint communication site members, follow the below PowerShell command. Here, I provided the URL of the communication site.

Get-SPOUser -Site https://szg52.sharepoint.com/sites/ITSoftware

After executing the above command, you will see all the site members on your console, as shown in the screenshot below.

get modern sharepoint site members using powershell

This is how we can get the SharePoint site members using the SharePoint Management Shell.

NOTE:

Follow the same PowerShell commands to get all the members of different SharePoint sites, like team site connected to the Microsoft 365 group, classic team site, communication site, and the team site without connected to the Microsoft 365 group.

Get SharePoint Site Members using PnP PowerShell

The Get-PnPUser command is used to get the list of SharePoint site members in PnP PowerShell. We can also retrieve the SharePoint site members based on their permissions.

Syntax:
Get site members based on their identity:

Get-PnPUser [-Identity <UserPipeBind>] [-Connection <PnPConnection>] 

Get site members who have specific access to the current site, including lists and libraries:

Get-PnPUser [-WithRightsAssigned] [-Connection <PnPConnection>] 

Get site members details who have specific access to the current site, including lists and libraries:

Get-PnPUser [-WithRightsAssignedDetailed] [-Connection <PnPConnection>]

Where;

  • Identity: It specifies the user ID, login name, or Microsoft account for the user identification.
  • Connection: You may optionally connect to a different site by executing the “Get-PnPConnection” or “Connect-PnPOnline” command.
  • WithRightsAssigned: It specifies the members with specific access to the current site, including lists and libraries.
  • WithRightsAssignedDetailed: It specifies the details of site members with specific access to the current site, including lists and libraries.

To get SharePoint site members, you need to establish a direct connection between the SharePoint Online site and PowerShell.

Example 1: Get all the SharePoint site members using PnP PowerShell

To get all the SharePoint site members using PnP PowerShell, you can use the following command:

 Get-PnPUser

To execute the above command, click on the RUN button. It will display SharePoint site members in the TERMINAL, as shown in the screenshot.

get sharepoint site members using pnp powershell

You can find both the default and custom members of the SharePoint site here.

Example 2: Get the SharePoint site member based on their identity using PnP PowerShell

Follow this command to get specific SharePoint site members based on their identity, such as user ID, title, login name, and email. You can also check whether the member is present or not using this identity.

Get-PnPUser -Identity "13"

After executing the above command, you will see a respected SharePoint site member in your TERMINAL, as shown below.

how to get sharepoint site members using pnp powershell

If the given identity is not found on the SharePoint site, it will show the “User cannot be found” error message.

Example 3: Get SharePoint site members who have specific permissions to access the site using PnP PowerShell

Follow the below PnP PowerShell command to get all the SharePoint site members who have the permissions to access the current site, including lists and libraries.

Get-PnPUser -WithRightsAssigned

Press the RUN button to execute the above command. The output will be displayed in the TERMINAL, as shown in the figure below.

get modern sharepoint site members using pnp powershell

You can see a list of all the members with the necessary permission to access the SharePoint site.

Example 4: Get SharePoint site members’ details who have specific permissions to access the site using PnP PowerShell

This PnP PowerShell command gets all the details of SharePoint site members who have permission to access the current site, including the lists and libraries.

Get-PnPUser -WithRightsAssignedDetailed

Click the RUN button to execute the above command. After execution, you will get all the individual SharePoint site member details in the TERMINAL, as shown in the figure.

get a sharepoint site members using pnp powershell

Example 5: Get SharePoint communication site members using PnP PowerShell

To get all the SharePoint communication site members, first connect the communication site with PnP PowerShell. Then, you can use the PnP PowerShell command to get site members. Follow the below PowerShell script to achieve this.

# connect the SharePoint communication site with PnP PowerShell
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/ITSoftware"

# Get all the SharePoint site members
Get-PnPUser 

Execute the above script by clicking the RUN button. You will get all the site members on your TERMINAL.

how to get a sharepoint site members using pnp powershell

This is how we can get the SharePoint site members using PowerShell commands.

In this article, I showed how to get SharePoint site members using SharePoint Online Management Shell and PnP PowerShell, with examples.

I hope these examples will be helpful when you try to retrieve the SharePoint site members.

Also, you may like some more articles: