SharePoint Online: How to Exclude a Site from Search Results?

Requirement: Exclude a Site from Search in SharePoint Online.

SharePoint Online search results are security trimmed by default, and users get search results from all sites to which they have access. However, there are some scenarios where you may want to prevent a site from appearing 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. In this post, we will discuss how to exclude a site from search results in SharePoint Online.

  1. Open the SharePoint Online site which you want to prevent from appearing in the search result. 
  2. Click on the Settings Icon and then choose “Site Settings”.
  3. On the Site Settings page, click on the “Search and offline availability” link under the “Search” section.
    sharepoint online exclude site from search
  4. 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 the 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 excludes site collection from search. Make sure you connect to the site collection (not the subsite!).

Exclude Site from Search Results using Query Rules

Here is an alternate approach to exclude content from the search using query rules:

  1. Navigate to your search center. Typically, at:
  2. Go to the Search Results page by entering some search query and clicking on search. 
  3. Once you are on the search results page (Pages/results.aspx), Click on Settings gear >> choose “Edit Page”.
  4. Locate the “Search Results” web part, and choose “Edit this web part” from its context menu. This opens the web part properties pane. 
  5. In the Web part properties panel, click on the “Change Query” button. You’ll get a Popup page to build your query.
  6. 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
  7. Save, Check-In and Publish the page! If you want to exclude multiple site collections, use OR operator. E.g. {searchboxquery} -Path:* OR -Path:*

You can also remove existing search results from the search index with the “Remove Search Results” page in the SharePoint Admin center! How to Remove Search Results from SharePoint Online?


Excluding a site from search results in SharePoint Online is a simple process that can be accomplished by editing the site’s crawl setting on the SharePoint Search Administration page. By setting the site’s crawl setting to “No”, we can prevent the site from appearing in search results. You can also set this property using PowerShell to automate the process. This can be useful for sites that contain sensitive or confidential information, or for sites that are not relevant to the majority of users. Keep in mind that it may take some time for the changes to take effect.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

6 thoughts on “SharePoint Online: How to Exclude a Site from Search Results?

  • Thanks for this, I am wondering do you know of a way to do this for OneDrive’s and in Bulk ?

  • How can we exclude multiple sites using Powershell script?

  • Does this also work for the modern sharepoint experience (Microsoft Search)?

  • THANK YOU!!!! This helped me so much with one of my queries you’re the best.

  • 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


Leave a Reply

Your email address will not be published. Required fields are marked *