Skip to content

Commit

Permalink
Merge pull request #669 from ganesh-sanap/spo-reindex-sites-clim365
Browse files Browse the repository at this point in the history
Sample Update - Reindex SharePoint sites. Closes #667
  • Loading branch information
pkbullock authored Mar 5, 2024
2 parents d78a828 + 08442bb commit 1be156b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
45 changes: 41 additions & 4 deletions scripts/spo-reindex-sites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugin: add-to-gallery

## Summary

When using SharePoint columns in search solutions, you may need to map crawled properties to managed properties and update the search schema. For example, you can map the crawled property `ows_Foo` to `RefinableString100` and use it as a filter in [KQL](https://learn.microsoft.com/en-us/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference). For more information, refer to [How Do Site Columns Become Managed Properties](https://learn.microsoft.com/en-us/microsoft-365/community/how-do-site-columns-become-managed-properties-thus-available-for-search).
When using SharePoint columns in search solutions, you may need to map crawled properties to managed properties and update the search schema. For example, you can map the crawled property `ows_Foo` to `RefinableString100` and use it as a filter in [KQL](https://learn.microsoft.com/sharepoint/dev/general-development/keyword-query-language-kql-syntax-reference). For more information, refer to [How Do Site Columns Become Managed Properties](https://learn.microsoft.com/microsoft-365/community/how-do-site-columns-become-managed-properties-thus-available-for-search).

If your schema change applies to existing content, you must schedule a re-index operation for the affected content in order to have the data populated into the search index.

Expand All @@ -22,30 +22,67 @@ This PnP PowerShell script streamlines the process of re-indexing sites, librari

```PowerShell
#Prompt for caution
Read-Host -Prompt "Are you sure you know what you are doing, and have read the text at https://pnp.github.io/script-samples/spo-reindex-sites/README.html?"
Read-Host -Prompt "Are you sure you know what you are doing, and have read the text at https://pnp.github.io/script-samples/spo-reindex-sites/README.html?"
#Set Parameters
$AdminCenterURL="https://contoso-admin.sharepoint.com"
$AdminCenterURL = "https://contoso-admin.sharepoint.com"
# Connect to SharePoint admin center
Connect-PnPOnline -Url $AdminCenterURL -Interactive
#Get SharePoint sites
$m365Sites = Get-PnPTenantSite -Detailed | Where-Object {($_.Url -like '*/teams-*' -or $_.Template -eq 'TEAMCHANNEL#1') -and $_.Template -ne 'RedirectSite#0' } #filter to exclude redirect sites and to include team channel sites in the list
$m365Sites | ForEach-Object {
# Connect to SharePoint site
Connect-PnPOnline -Url $_.Url -Interactive
#Request Reindex
Request-PnPReIndexWeb
Write-host "Reindexing: " $web $_.Url
Write-host "Reindexing: " $_.Url
}
# Disconnect SharePoint online connection
Disconnect-PnPOnline
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

# [CLI for Microsoft 365](#tab/cli-m365-ps)

```powershell
#Prompt for caution
Read-Host -Prompt "Are you sure you know what you are doing, and have read the text at https://pnp.github.io/script-samples/spo-reindex-sites/README.html?"
#Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}
#Get SharePoint sites
$m365Sites = m365 spo site list | ConvertFrom-Json | Where-Object {$_.Url -like '*/sites/*' -and $_.Template -ne 'RedirectSite#0' } #filter to include sites with "/sites/" managed path and to exclude the redirect sites
$m365Sites | ForEach-Object {
Write-host "Requesting reindexing for: " $_.Url
#Request Re-indexing of SharePoint site
m365 spo web reindex --url $_.Url
}
#Disconnect SharePoint online connection
m365 logout
```

[!INCLUDE [More about CLI for Microsoft 365](../../docfx/includes/MORE-CLIM365.md)]

***

## Contributors
| Author(s) |
|-----------|
| [Reshmee Auckloo (script)](https://github.com/reshmee011)|
| [Mikael Svenson (caution text)](https://github.com/wobba)|
| [Ganesh Sanap (script)](https://ganeshsanapblogs.wordpress.com/about) |


[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
Expand Down
27 changes: 24 additions & 3 deletions scripts/spo-reindex-sites/assets/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"title": "Reindex SharePoint sites",
"url": "https://pnp.github.io/script-samples/spo-reindex-sites/README.html",
"creationDateTime": "2024-02-19",
"updateDateTime": "2024-02-23",
"shortDescription": "Keeping your SharePoint environment up-to-date is crucial, especially after making schema changes - this script streamlines the process of reindexing sites, libraries, or lists. ",
"updateDateTime": "2024-03-03",
"shortDescription": "Keeping your SharePoint environment up-to-date is crucial, especially after making schema changes - this script streamlines the process of reindexing sites, libraries, or lists.",
"longDescription": ["The script should **ONLY** be used for the scenario where a schema mapping affects ALL content in your tenant. Site re-indexing may add stress to the search system and take an extended amount of time to complete. Re-crawls of sites with more than one million items can potentially take weeks to process. Subsequent index updates could be delayed until the re-indexing is complete, leading to out-of-date search results. Make sure to only initiate a site re-index after making changes that require all items to be reindexed."],
"products": [
"SharePoint"
Expand All @@ -19,12 +19,22 @@
"tags": [
"Connect-PnPOnline",
"Get-PnPTenantSite",
"Request-PnPReIndexWeb"
"Request-PnPReIndexWeb",
"Disconnect-PnPOnline",
"m365 status",
"m365 login",
"m365 spo site list",
"m365 spo web reindex",
"m365 logout"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.3.0"
},
{
"key": "CLI-FOR-MICROSOFT365",
"value": "7.5.0"
}
],
"thumbnails": [
Expand All @@ -37,6 +47,12 @@
}
],
"authors": [
{
"gitHubAccount": "ganesh-sanap",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/25476310?v=4",
"name": "Ganesh Sanap"
},
{
"gitHubAccount": "wobba",
"company": "",
Expand All @@ -55,6 +71,11 @@
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
},
{
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
"url": "https://aka.ms/cli-m365"
}
]
}
Expand Down

0 comments on commit 1be156b

Please sign in to comment.