We need to remove 150 sites from Search Index. We have to make sure they don't show up in search results by turning off that option for each site. The normal way of doing this is too slow for so many sites. We use a faster PowerShell script method to handle 150 sites at once.
Regular method
By default, the option Allow this site to appear in Search results is set to Yes for all Site collections in Sharepoint online. This means the site content can show up in search results.
On the site, select Settings (Wheel) icon., and then select Site settings. If you don't see Site settings, select Site information, and then select View all site settings.Under Search, click Search and offline availability.
In the Indexing Site Content section, under Allow this site to appear in Search results, select Yes to allow the content of the site to appear in search results.
NOTE: Search results are always security trimmed, so users will only see content they have permission to see.
PowerShell Script Method
List all the sites in a CSV file with URL as Header (As shown below).
# symbol in PowerShell script is used for comments.
# Connect to Admin Center
$adminSiteUrl = "https://gurram-admin.sharepoint.com/"
$adminConnection = Connect-PnPOnline -Url $AdminSiteUrl -Interactive
$CSVImport = "D:\Sites.csv"
$SitesCollections = Import-CSV -Path $CSVImport
ForEach($Site in $SitesCollections)
{
$siteCollectionConnection = Connect-PnPOnline -Url $Site.URL -Interactive
Set-PnPSite -Identity $Site.URL -DenyAndAddCustomizePages $false
$Web = Get-PnPWeb -Connection $siteCollectionConnection
#Indexing Site Content = Yes(false), = No(true)
$Web.NoCrawl = $false
$Web.Update()
Invoke-PnPQuery
#To unlock the site (-LockState Unlock), To lock the site (-LockState ReadOnly)
#we did not use the below option, because we want to delete sites later
Set-PnPSite -Identity $Site.URL -LockState ReadOnly
#to know the completed site
write-host $Site.URL
}
No comments:
Post a Comment