SharePoint Online: Hide Search Box In the Top Navigation Suite bar

Requirement: Hide Search Box in the Top Navigation Suite bar in SharePoint Online

How to Remove Search Box from Top Navigation Suite bar?
Search box in SharePoint Online top navigation suite bar can be hidden with this PowerShell script:
#Set Parameters
$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 Web object
    $Web = $Ctx.Web

    #Disable search in navigation bar
    $Web.SearchBoxInNavBar = 3
Catch {
    write-host -f Red "Error:" $_.Exception.Message
SearchBoxInNavBar enumeration values:
  • Inherit = 0
  • AllPages = 1
  • ModernOnly = 2
  • Hidden = 3
We can also set search box settings using PnP PowerShell.
#Set Parameters
$SiteURL = ""

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Hide Searchbox in Navigation bar
Set-PnPSearchSettings -SearchBoxInNavBar Hidden -Scope Web -Force

This hides the search box from top navigation bar of the SharePoint Online site in few minutes. To Enable the search box back in Navigation bar, use:
Set-PnPSearchSettings -SearchBoxInNavBar ModernOnly -Scope Web 
Also, you can set the search box visibility at site collection level by changing the scope parameter from "Web" to "Site"

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.