SharePoint Site Lock and Remove from Search Results

At Sympraxis, we often work with clients who have been using SharePoint for a long time. In many of these cases, they have been using SharePoint basically as a cloud-based file server. At some point in the past, they have done a lift and shift from “on premises” servers (wherever they may live) into SharePoint on premises or SharePoint Online. They are getting little value for their use of the platform, and they want to move up the Microsoft 365 Maturity Model.

One of the things we often need to do is migrate content from its current location into a more refined and purpose-built site topology and information architecture.

When we do that migration, we don’t want to delete the old site(s). Instead, we want to lock them from accidental updates and remove them from the search index. Since we’re migrating the content into new locations, we don’t want to old content to show up in search results.

The PowerShell below is useful in that it allows us to take care of those two steps easily. It’s meant as an example, but it is working code. You might more realistically wrap this in a foreach to apply to multiple sites at the same time.

$tenantName = "your tenant name here"
$spRoot = "https://$($tenantName).sharepoint.com"
$siteCollectionUrlFragment = "foo" # Part of the URL after /sites/, e.g., HRTeam, Marketing, etc.

# Work on this Site Collection
$siteCollection = "$(spRoot)/sites/$($siteCollectionUrlFragment)"

# Connect to Admin Center
$adminSiteUrl = "https://$($tenantName)-admin.sharepoint.com/"
$adminConnection = Connect-PnPOnline -Url $AdminSiteUrl -Interactive
 
# Connect to Site Collection
$siteCollectionConnection = Connect-PnPOnline -Url $siteCollection -Interactive

# Needed to set NoCrawl
Set-PnPSite -Identity $siteCollection -DenyAndAddCustomizePages $false
 
# Exclude Site Collection from Search Index
$Web = Get-PnPWeb -Connection $siteCollectionConnection
$Web.NoCrawl = $true
$Web.Update()
Invoke-PnPQuery

# Lock the site
Set-PnPSite -Identity $siteCollection -LockState ReadOnly

Similar Posts

2 Comments

    1. Absolutely, and we often do this as well. It’s a bit of a different use case, as in my example, the existing classic sites are getting full retirement rather than needing to be archived.

      M.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.