Hide OOB Search Box in SharePoint Navigation Bar

All Scripts

Hello All,

Greetings. Welcome to the PowerShell hub.

Today, I’m sharing a PowerShell script that demonstrates how to hide the search box from a SharePoint site navigation bar.

Background

On our SharePoint site, we have the OOB SharePoint search box displayed by default.

Since our project uses a custom search solution, we need to hide the OOB search box to avoid confusion and provide a seamless user experience.

Image 1 : SharePoint site – OOB search box

Steps to hide the OOB search box on a SharePoint site

  • Here, we will use PnP PowerShell cmdlets
  • Connect to the SharePoint site
    • We will connect to the tenant using PnP PowerShell CMDLET – Connect-PnPOnline
    • To connect to the tenant using Connect-PnPOnline we will require following values
      • SharePoint site URL – site where we need to hide the OOB search box
      • Application ID / Client ID – The Client ID of the Entra ID Application
      • Certificate Path – Path to the certificate containing the private key (*.pfx)
      • Certificate Password – Password for certificate
      • Tenant ID
    • Initialize the required variables
PowerShell
$SharePointSiteUrl = "https://knowledgejunction1.sharepoint.com/sites/TestNavBar"
$ClientId = "<client id>>"
$CertificatePath = "C:\Prasham\m365KJ.pfx"
$CertificatePassword = "<certificate password>>"
$CertificatePassword = (ConvertTo-SecureString -AsPlainText $CertificatePassword -Force)
  • Using above variables, connect to the tenant using We will connect to the tenant using PnP PowerShell CMDLET – Connect-PnPOnline
PowerShell
Connect-PnPOnline
-Url $SharePointSiteUrl -ClientId $ClientId
-CertificatePath $CertificatePath
-CertificatePassword $CertificatePassword
-Tenant 'knowledgejunction1.onmicrosoft.com' -WarningAction Ignore
  • Once we connected to SharePoint site, we will use Set-PnPSearchSettings PowerShell CMDLET to hide the search box in navigation bar
PowerShell
Set-PnPSearchSettings -SearchBoxInNavBar Hidden
  • Once script executed successfully refresh the page.

Complete script

PowerShell
$SharePointSiteUrl = "https://knowledgejunction1.sharepoint.com/sites/TestNavBar"
$ClientId = "<client id>>"
$CertificatePath = "C:\Prasham\m365KJ.pfx"
$CertificatePassword = "<certificate password>>"
Connect-PnPOnline
-Url $SharePointSiteUrl -ClientId $ClientId
-CertificatePath $CertificatePath
-CertificatePassword $CertificatePassword
-Tenant 'knowledgejunction1.onmicrosoft.com'
-WarningAction Ignore
Set-PnPSearchSettings -SearchBoxInNavBar Hidden
PowerShell script to hide OOB search box in SharePoint site navigation bar
Image: PowerShell script to hide OOB search box in SharePoint site navigation bar
Search box is hidden after executing the PowerShell CMDLET
Image: Search box is hidden after successfully execution of PowerShell CMDLET

References

Thank you for reading ! Have a great time ahead :)

Feel free to discuss anything about PowerShell scripts. HAPPY to HELP!

Leave a comment