Thursday 12 July 2018

Extract site classification report of Modern SharePoint sites using PnP-PowerShell

The Classification value of a SharePoint modern Team Site is not exposed through CSOM (at the time of writing this) unlike for the Communication Sites. This property for Team Sites exists on the Office 365 Group object (modern team site has a Office 365 Group connected to it) and can be extracted through a Graph API call.

The latest PnP-PowerShell release supports extracting classification value of a Team Site (Office 365 Group) using the Get-PnPUnifiedGroup command. This makes it very easy to extract a report of classification values of all the Team Sites in a tenant.

Below are a couple of scripts to export classification reports of all the modern sites - both Team and Communication sites in a tenant using PnP-PowerShell in just a couple of lines of code.

Make sure you have  2.28.1807.0 release installed before running the scripts. https://github.com/SharePoint/PnP-PowerShell/releases


Extract report for Team Sites :


To extract the classification report for Team Sites, we first need to connect to Microsoft Graph. Register an APP in https://apps.dev.microsoft.com and provide it appropriate permissions to be able to read Office 365 Group information. Also make sure you consent the app. Here is some documentation on how to do this




The report extraction might take some time as for each Office 365 Group, a separate call has to be made to the Graph API to fetch its classification value. This will change soon as PnP Core has been updated to the Latest Graph Version which supports extracting the classification value without a separate Graph call. Till this change is available, the report extraction process will be relatively slow :)

















Extract report for Communication sites :


For communication sites, we first fetch all the Communication sites using the Get-PnPTenantSite command and filtering on the Template property. Then we get the Site object of each Communication Site and include the CLASSIFICATION property.

Execute the below command with the tenant admin account by replace the placeholders with relevant values in the below script













No comments:

Post a Comment