kwizcom banner advertisement

SharePoint Online: Remove List from Search using PowerShell

By default, all SharePoint Online lists and libraries appears 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:
To exclude a list or library from search index using 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.
    sharepoint online remove list from search
  • Click OK to commit changes.
This setting allows or disallows SharePoint Online crawler to index the list. Wait for 4 to 6 Hours and this list should be removed from search results.

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
#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 Seach Crawl
Set-SPOListCrawl -ListName "Documents" -NoCrawl $True
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 PowerShell SharePoint Online: Remove List from Search using PowerShell Reviewed by Salaudeen Rajack on October 18, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.