SharePoint Online: Remove List from Search using PowerShell
By default, all SharePoint Online lists and libraries appear in search results. There are some cases you want to remove a particular list's contents from appearing in search results. Say e.g. You want to hide images library's content from appearing in search results.
How to Remove a list from SharePoint Online Search:
You can configure a specific list to be excluded from search. To exclude a list or library from search index using the user interface, go to :
How to Remove SharePoint Online List from Search using PowerShell:
Lets use PowerShell to exclude the list or library from SharePoint Online search.
PowerShell script to Disable List from SharePoint Online Search:
Lets make the script as re-usable function. To make list searchable, simply set the "NoCrawl" parameter to "True"
SharePoint Online: Remove List from Search using PnP PowerShell
How to Remove a list from SharePoint Online Search:
You can configure a specific list to be excluded from search. To exclude a list or library from search index using the user interface, go to :
- List Settings >> Click on "Advanced Settings"
- Scroll down and under Search section, select "Yes" for "Allow items from this document library to appear in search results?" Option.
- Click OK to commit changes.
How to Remove SharePoint Online List from Search using PowerShell:
Lets use PowerShell to exclude the list or library from SharePoint Online search.
#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #Set parameter values $SiteURL="https://crescent.sharepoint.com" $ListName = "Documents" Try { #Get Credentials to connect $Cred= Get-Credential $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Credentials #Get the list $List = $Ctx.Web.Lists.GetByTitle($ListName) #Exclude from Search Results $List.NoCrawl = $True $List.Update() $Ctx.ExecuteQuery() Write-host "List has been excluded from Search Index!" -f Green } Catch { write-host -f Red "Error Excluding List from Search Index!" $_.Exception.Message }
PowerShell script to Disable List from SharePoint Online Search:
Lets make the script as re-usable function. To make list searchable, simply set the "NoCrawl" parameter to "True"
#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #Function to Enable or Disable Search Crawl Function Set-SPOListCrawl() { Param ([string]$ListName,[bool]$NoCrawl) Try { #Get the list $List = $Ctx.Web.Lists.GetByTitle($ListName) #Enable/Disable List from Search Results $List.NoCrawl = $NoCrawl $List.Update() $Ctx.ExecuteQuery() Write-host "List Search Crawl Settings has been Updated!" -f Green } Catch { write-host -f Red "Error Setting List Search Crawler Settings!" $_.Exception.Message } } #Set parameter values $SiteURL="https://crescent.sharepoint.com/" #Get Credentials to connect $Cred= Get-Credential $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Credentials #Call the Function to Exclude a list from Search Crawl Set-SPOListCrawl -ListName "Documents" -NoCrawl $TrueThis removes the content of the list or library from search results. Here is my another article on excluding list or library from search index in SharePoint on-premises: How to Exclude SharePoint Site or List from Search Index?
SharePoint Online: Remove List from Search using PnP PowerShell
#Config Variables $SiteURL = "https://crescenttech.sharepoint.com" $ListName = "Team Documents" #Connect to PNP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #Get the Context $Context = Get-PnPContext #Get the List $List = Get-PnPList -Identity $ListName If($List) { #Set "NoCrawl" flag to exclude list from search $List.NoCrawl = $True $List.Update() $Context.ExecuteQuery() Write-host -f Green "List Excluded from Search Index Successfully. Changes takes effect after the next crawl!" } else { Write-host -f Yellow "Could not find List '$ListName'" }
No comments:
Please Login and comment to get your questions answered!