SharePoint Online: How to Exclude Site from Search Results?

Requirement: Exclude Site from Search in SharePoint Online

How to Exclude a SharePoint Online Site from Search?
SharePoint Online search results are security trimmed by default. Users get search results from all sites where they have access. However, there are some scenarios where you may want to prevent a site to appear in search results, E.g. We've got a document archive site collection for backup purposes, and we don't want results from this site to appear in global search results.
  • Open the SharePoint Online site which you want to prevent to appear in the search result. 
  • Click on Settings Icon and then choose "Site Settings"
  • In Site Settings page, click on the "Search and offline availability" link under the "Search" section.
    sharepoint online exclude site from search
  • Set the "Allow this site to appear in search results?" option to "No" in the Indexing Site Content section, Then click on OK.
    sharepoint online exclude site collection from search
These changes take effect after the next crawl - The site and all contents from it will not appear in the search result. 

SharePoint Online: Exclude Site from Search using PowerShell
To exclude a SharePoint Online site collection from the search index, use this PowerShell script:
#Load SharePoint Online 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"
##Variables for Processing
$SiteUrl = ""

#Get Credentials to connect
$Cred= Get-Credential
Try {    
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Get the Web
    $Web = $Ctx.Web

        Write-host -f Yellow "Site is Already excluded from Search Index!"
        #Exclude Site from Search
        $Web.NoCrawl = $True
        Write-host -f Green "Site is Excluded from Search Index Successfully!"
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

PnP PowerShell to Exclude a Site collection from Search in SharePoint Online 
We can also use PnP PowerShell to exclude a site from SharePoint Online search index.
$SiteURL= ""

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Exclude Root Web of the Site Collection from Search Index
$Web = Get-PnPWeb
$Web.NoCrawl = $true
This exclude site collection from search. Make sure you are connecting to the site collection (not sub-site!).

Exclude from Search Results using Query Rules
Here is an alternate approach to exclude content from search using query rules:
  • Navigate to your search center. Typically, at:
  • Go to Search Results page by entering some search query and clicking on search. 
  • Once You are in Search results page (Pages/results.aspx), Click on Settings gear >> choose "Edit Page".
  • Locate "Search Results" web part, and choose "Edit this web part" from its context menu. This opens the web part properties pane. 
  • In the Web part properties panel, Click on "Change Query" button. You'll get a Popup page to build your query.
  • In the "Build your query" dialogue window, select "Path" in the property filter dropdown. Change the parameter to "Not starts with". For the value, select "Manual value" and then type the URL for the site you want to exclude and then click the button "Add property filter". This appends the "Query Text" box with -Path:https://site-to-remove/*. E.g: {searchboxquery} -Path:* 
    sharepoint online exclude from search results
  • Save, Check-In and Publish the page! If you want to exclude multiple site collections, use OR operator. E.g. {searchboxquery} -Path:* OR -Path:*


  1. In my tenant there is folder called "Test123" in all the SharePoint online sites(Approx 500 sites), I would like to exclude the particular folder from search results and index in SharePoint online. Is there any direct way to achieve this requirement

    1. Query rule text with "-Path:Test123" should fulfill your requirements!


Please Login and comment to get your questions answered!

Powered by Blogger.