Recently, I have been tasked with getting the site user’s report in SharePoint sites in our organization Tenant. There are tools and other ways to get it. Here I have used PnP PowerShell version and the concept of PS Custom Object to achieve this task. In this article, we will see how to get the Site Users report using PnP PowerShell and PS Custom Object.

SharePoint-2013-Hosting

What is PS Custom Object?

This is a new property introduced in PowerShell 3.0 version and above, which helps in creating structured data, and with this data it makes it easier to

  • Query the data
  • Import and export the data
  • Storing the data while working in a session

The details about PSCustomObject is nicely explained by Kevin in his blog and I would highly recommend checking it.

Pre-Requisites

Before proceeding you need to have the following configurations.

  • Access to your organization tenant as SharePoint Admin or Global Admin or access to the sites as Site Collection admin where you want to get the site user’s report
  • PnP PowerShell module installed. Please investigate the references section on how to install the PowerShell module.

Steps

Please follow the below steps to get the site user’s report.

Step 1

Connect to the SharePoint site

Step 2

Get the Permission Groups in the SharePoint site.

Step 3

For each user in Group get the required information and write to object. Here I am only getting Email, PrincipalType, Title, LoginName

If you are interested in getting additional properties you can also add them. By default, it gets the following properties, which can be found by querying a member with select * parameter.

Step 4

Export the object data into CSV.

Validation

Below is the input format of the CSV file.

Below is the output CSV after the script run completes.

Below is the complete script