Site icon Joanne C Klein

Adaptive Policy Scopes targeting SharePoint Site Templates

Reading Time: 5 minutes

An Adaptive Policy Scope is a flexible feature in Microsoft 365 Information Governance and Records management used when publishing retention policies and retention label policies to locations across your tenant. It’s flexible because it provides the ability to filter the SharePoint sites your policies are published to based on a site’s properties.

When building the filter query for your SharePoint adaptive policy scope, you have 2 options:

As of January 2024, the built-in site properties available in the simple query builder drop down are Site URL and Site name (custom site properties are also available however this requires you to configure them first).

However, if we switch to the advanced query builder instead, we can use additional site properties found in the SharePoint search index. The property I’d like to focus on for this post is the built-in property, site template. If we used the site template in the query when building our SharePoint adaptive scope, this may be helpful in scenarios where retention controls need to be published to sites of a specific template. You can of course combine the site template filter with other conditions as required to include/exclude sites to suit your retention needs.

To demonstrate, I’ve set up 5 SharePoint Adaptive policy scopes each targeting a different site template:

Adaptive Policy Scopes for testing are listed below:

Because SharePoint adaptive scope queries are search-based, we must know which managed property to search on to filter by the site template. The crawled property, ows_sitetemplate, is mapped to the pre-built managed property, SiteTemplate as shown in the tenant’s search schema:

This means we must use the SiteTemplate managed property in the KQL query. Below is an example of the query format used in the advanced query builder to include all Modern Communication sites in the scope: (all queries must be entered in the advanced query builder)

Following the same query format above, here’s the results of the 5 adaptive scope queries for each of the site templates along with my observations:


1 – Microsoft 365 Group sites


2 – Modern Communication sites


3 – OneDrive sites

**This scope was a bit of a trick… read on. 🙂


4 – Teams’ Private Channel Sites


5 – Team sites with no Microsoft 365 Group

SiteTemplate=STS NOT SPSiteUrl:contentTypeHub


Validation

You can do some cursory validation thru the UI to ensure the correct sites have been added to your scope or use PowerShell if the list of sites being added is large (more likely in production tenants).

Validating thru the UI… use the SharePoint Admin Center, Teams Admin Center, or Microsoft Search to validate.

In the SharePoint Admin Center, you can use the below filters on the Active sites view to ensure the correct number/names of sites have been returned:

In the Teams Admin Center, you can see the number of Private channels per Team which will equate to Private Channel sites.

For any of the site templates (GROUP, SITEPAGEPUBLISHING, STS, and TEAMCHANNEL), you can also use the same query you enter in the advanced query builder in the Microsoft Search box along with the Sites vertical to validate:

Validating thru PowerShell… I’ve used the SharePointOnlinePowerShell module to export the results of each site template below to a .csv file for validation.

Get-SPOSite -Template “<template name>”| Select Url > <File location and name.csv>

If you have more conditions in your query, you can also execute your adaptive scope query using search cmdlets in PnP PowerShell and save the results to a file. Here is an example script to export all Modern Communication sites to a .csv file:

#Config Variables
$SiteURL = "https://CONTOSO.sharepoint.com/"
$SearchQuery = "SiteTemplate=SITEPAGEPUBLISHING AND ContentClass=STS_Site"
$CSVFile = "C:\~Templates\YOURFILENAMEGOESHERE.csv"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
#Run Search Query
$SearchResults = Submit-PnPSearchQuery -Query $SearchQuery -All

#Collect Data from search results
$Results = @()
ForEach ($ResultRow in $SearchResults.ResultRows)
{
$Results += [pscustomobject] @{
SiteName = $ResultRow["SiteName"]
}
}
#Export results to CSV
$Results | Export-Csv -Path $CSVFile -NoTypeInformation

Wrap-up

Having a familiarity with SharePoint site properties is an advantage when designing SharePoint adaptive scopes to suit retention requirements. Site templates is one example of a property you could use to assist. Hope you found this helpful!

Thanks for reading.

-JCK

Exit mobile version