As you probably know O365 groups have associated Sharepoint Online site behind. It may be needed to fetch only those sites which have associated O365 group via Sharepoint Search and KQL. In this post I will show how to do that and in the future post I will describe how to fetch only those sites which are not associated with O365 groups.
Modern Team sites which are associated with O365 group are created using Groups template. I.e. in order to get all sites associated with groups we may use the following KQL query:
(contentclass:STS_Site OR contentclass:STS_Web) WebTemplate:GROUP
It will work however there may be problem with old sites which were "groupified". I.e. regular site could be connected to O365 site - this procedure is called groupifying (see Connect to a Microsoft 365 group). Above query won't return such sites.
Another approach is based on the fact that groupified sites contain special property bag properties which contain information about connected group:
- GroupAlias
- GroupDocumentsListId
- GroupDocumentsUrl
- GroupId
- GroupType
By default custom property bag properties are not searchable but they can be made searchable by adding them to Indexed Property Bag which can be done via PowerShell:
Connect-PnPOnline -Url "http://{tenant}.sharepoint.com" Set-PnPPropertyBagValue -Key "customProperty" -Value "foo" -Indexed
Here is good article which explains this topic: What Are Indexed Property Bags And How To Use Them For SharePoint Site.
The good thing is that at least GroupId looks like indexed by default. This gives us possibility to use another KQL for getting sites connected with O365 groups:
(contentclass:STS_Site OR contentclass:STS_Web) GroupId<>""
This query will work also with groupified sites.
Update 2021-02-25: see also article which shows how to fetch sites which are not associated with O365 groups: Fetch Sharepoint Online sites which are not associated with O365 groups via Sharepoint Search KQL.
Good article.
ReplyDelete