ADAPTIVE POLICY SCOPES TARGETING SHAREPOINT SITE TEMPLATES

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:

  • A simple query builder provides a dropdown where you select properties from a provided list
  • An advanced query builder where you enter your own query based on the Keyword Query Language syntax using an expanded list of properties from the SharePoint search index

At the time of this writing (April 2022), 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:

  • Microsoft 365 Group-backed site
  • Modern Communication site
  • OneDrive for Business site
  • Private channel site
  • Team site not backed by a Group and Team site (classic experience)

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 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

  • Scope nameInclude all M365 Group Sites
  • Site template value in search index: GROUP
  • KQL query for Adaptive scope: SiteTemplate=GROUP
  • My observations: all Microsoft 365 Groups’ sites were successfully added to scope

2 – Modern Communication sites

  • Scope nameInclude all Modern Comm Sites
  • Site template value in search index: SITEPAGEPUBLISHING
  • KQL query for Adaptive scope: SiteTemplate=SITEPAGEPUBLISHING
  • My observations: all Modern Communication sites were successfully added to scope

3 – OneDrive sites

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

  • Scope nameInclude all OneDrive sites
  • Site template value in search index: SPSPERS
  • KQL query for Adaptive scope: SiteTemplate=SPSPERS
  • My observations: although all OneDrive sites were successfully added to scope, I wouldn’t use this technique to include them in a scope. If you want to publish a retention policy and/or label policy to all OneDrives, then use a static scope rather than an adaptive scope and select the OneDrive location during the publish process. If instead of publishing to all OneDrives, you want to publish to specific OneDrive sites, create a User Adaptive scope instead of a SharePoint Adaptive scope and enter the criteria to include/exclude users’ OneDrives in the scope conditions.
  • Link: Building Advanced Queries for Users and Groups with Adaptive Policy Scopes

4 – Teams’ Private Channel Sites

  • Scope nameInclude all Private Channel sites
  • Site template value in search index: TEAMCHANNEL
  • KQL query for Adaptive scope: SiteTemplate=TEAMCHANNEL
  • My observations: all Microsoft Teams’ Private Channel sites were successfully added to scope

5 – Team sites with no Microsoft 365 Group

  • Scope nameInclude all Team Sites with no Group
  • Site template value in search index: STS
  • KQL query for Adaptive scope: SiteTemplate=STS
  • My observations: BOTH Team sites not backed by a Microsoft 365 Group AND Team sites (classic experience) were successfully added to scope.
  • WARNING! this query ALSO added the built-in ~sites/contentTypeHub site which you should exclude. You can do this by adding the site URL to the condition as follows:

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
ConnectPnPOnline Url $SiteURL UseWebLogin
#Run Search Query
$SearchResults = SubmitPnPSearchQuery -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.

This blog is part of SharePoint Week. Find more here.

About the Author:

Joanne Klein is the owner of NexNovus, a SharePoint and Office 365 consulting company. She is an Advanced Compliance specialist within the Microsoft 365 cloud, has over 10 years of experience in SharePoint and is a Microsoft MVP in Office Apps & Services.

Reference:

Klein, J. (2022). ADAPTIVE POLICY SCOPES TARGETING SHAREPOINT SITE TEMPLATES. Available at: https://joannecklein.com/2022/04/10/adaptive-policy-scopes-targeting-sharepoint-site-templates/ [Accessed: 28th April 2022]. 

Share this on...

Rate this Post:

Share:

Topics:

SharePoint

Tags: