Microsoft 365 : PnP PowerShell – Identifying Sites with Spaces Content

Hi All,
Greetings for the day!
Recently there is MAJOR UPDATE from Microsoft related to SharePoint spaces.
MAJOR UPDATE : Microsoft SharePoint – The “spaces” feature will retire.
We have detailed article on this MAJOR UPDATE. Microsoft SharePoint: MAJOR UPDATE – The “spaces” feature will start retiring from March 10, 2025. – https://knowledge-junction.in/2025/02/12/sharepoint-update-spaces-feature-will-retire/
In this article we will discuss how to identify all spaces content in my tenant. We will discuss PowerShell script.
You can identify spaces content in a site by navigating to the Pages library. And looking for any files with the Content Type “Space”.

PREREQUISITES
- PowerShell 7.4.4 or later to use PnP PowerShell
- Entra ID Application
- The user running this script must have access to all sites in the tenant
Details
- Declare the required variables
#region variable declaration
#CSV file path in which we need to store the sites where spaces feature is enabled.
$SpacesSites = "C:\Users\prasham\Documents\Prasham\Articles\PowerShell\spacescontent.csv"
#CSV file path in which errors are logged
$ReportError = "C:\Users\prasham\Documents\Prasham\Articles\PowerShell\spacescontenterror.csv"
#client id
$entraAppClientID = "768437d9-957a-4a5e-b91a-f68213bf6d33"
#empty array declarations
$results = @()
$errorobj = @()
#endregion
- Define the Spaces feature GUIDs
#use this GUID to check for sites where the feature is currently enabled
#$featureGuid = "2AC9C540-6DB4-4155-892C-273957F1926"
#this GUID checks for sites that have ever had the feature enabled and may have spaces
$featureGuid = "f4c52091-703d-431c-ac2d-41f9f257052a"
- Connect to SharePoint Online
$adminUrl = "https://knowledgejunction1-admin.sharepoint.com"
Connect-PnPOnline -Url $adminUrl -Interactive -ClientId $entraAppClientID
- Get all site collections
$sites = Get-PnPTenantSite -Detailed
- Traverse through all the sites, check if spaces feature is activated
foreach ($site in $sites) {
try{
Write-Host $site.Url
# Connect to the site
Connect-PnPOnline -Url $site.Url -Interactive -ClientId $entraAppClientID
# Check if the MixedReality feature is enabled
$feature = Get-PnPFeature -Identity $featureGuid -Scope Site
if ($feature.DefinitionId -eq $featureGuid) {
# Get the pages library
$pagesLibrary = Get-PnPList -Identity "SitePages"
# Get all pages with content type "Space"
$spacePages = Get-PnPListItem -List $pagesLibrary | Where-Object {$_.FieldValues.MetaInfo -match 'ContentTypeId:SW\|0x0101009D1CB255DA76424F860D91F20E6C41180043153F945E98468297E67C3EEE43AB7000'}
# Get the total number of spaces
$totalSpacePages = $spacePages.Count
}catch{
Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
$errorobj +=[pscustomobject]@{
'Exception Message' = $_.Exception.Message
'Inner Exception'=$_.Exception.InnerException
'URL' = $site.Url
}
- Write the result in array so that we can export it to CSV file
$results += [PSCustomObject]@{
SiteUrl = $site.Url
FeatureGuid = $featureGuid
TotalSpaces = $totalSpacePages
}#$results += [PSCustomObject]@
- Export the result to CSV file
$results | Export-Csv $SpacesSites -NoTypeInformation
COMPLETE SCRIPT
<#
.SYNOPSIS
Get all SharePoint sites with the Spaces feature enabled
.DESCRIPTION
This script enlist all SharePoint sites where spaces feature enabled.
It also outputs the list of sites in CSV file.
Sites are written to the path of CSV file assigned to $SpacesSites variable
It also outputs errors in error file.
Errors are written to the path of CSV file assigned to $ReportError variable
.EXAMPLE
Get-SpacesContentInTenant
#>
#region variable declaration
$SpacesSites = "C:\Users\prasham\Documents\Prasham\Articles\PowerShell\spacescontent.csv"
$ReportError = "C:\Users\prasham\Documents\Prasham\Articles\PowerShell\spacescontenterror.csv"
$entraAppClientID = "768437d9-957a-4a5e-b91a-f68213bf6d33"
$results = @()
$errorobj = @()
#endregion
# Define the Spaces feature GUIDs
#$featureGuid = "2AC9C540-6DB4-4155-892C-273957F1926" #use this GUID to check for sites where the feature is currently enabled
$featureGuid = "f4c52091-703d-431c-ac2d-41f9f257052a" #this GUID checks for sites that have ever had the feature enabled and therefore may have spaces in its library
# Connect to SharePoint Online
$adminUrl = "https://knowledgejunction1-admin.sharepoint.com"
Connect-PnPOnline -Url $adminUrl -Interactive -ClientId $entraAppClientID
# Get all site collections
$sites = Get-PnPTenantSite -Detailed
#traverse through all the sites, check if spaces feature is activated
foreach ($site in $sites) {
try{
Write-Host $site.Url
# Connect to the site
Connect-PnPOnline -Url $site.Url -Interactive -ClientId $entraAppClientID
# Check if the MixedReality feature is enabled
$feature = Get-PnPFeature -Identity $featureGuid -Scope Site
if ($feature.DefinitionId -eq $featureGuid) {
# Get the pages library
$pagesLibrary = Get-PnPList -Identity "SitePages"
Write-Host "Feature On"
# Get all pages with content type "Space"
$spacePages = Get-PnPListItem -List $pagesLibrary | Where-Object {$_.FieldValues.MetaInfo -match 'ContentTypeId:SW\|0x0101009D1CB255DA76424F860D91F20E6C41180043153F945E98468297E67C3EEE43AB7000'}
# Get the total number of spaces
$totalSpacePages = $spacePages.Count
# Store the result
$results += [PSCustomObject]@{
SiteUrl = $site.Url
FeatureGuid = $featureGuid
TotalSpaces = $totalSpacePages
}#$results += [PSCustomObject]@
}#if ($feature.DefinitionId -eq $featureGuid)
}catch{
Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
$errorobj +=[pscustomobject]@{
'Exception Message' = $_.Exception.Message
'Inner Exception'=$_.Exception.InnerException
'URL' = $site.Url
}
}
}#foreach ($site in $sites) {
# Output the results
#$results | Format-Table -AutoSize
$results | Export-Csv $SpacesSites -NoTypeInformation
$errorobj | Export-Csv $ReportError -NoTypeInformation
REFERENCES
- Installing PnP PowerShell – https://pnp.github.io/powershell/articles/installation.html
- Microsoft SharePoint: MAJOR UPDATE – The “spaces” feature will start retiring from March 10, 2025. – https://knowledge-junction.in/2025/02/12/sharepoint-update-spaces-feature-will-retire/
Thank you for reading. Have a great time ahead! LIFE IS BEAUTIFUL 🙂

You must be logged in to post a comment.