0

I need to disable search in site level using client Object Model. and search textbox in the top navigation.

Need help on this.

Thank you,

1 Answer 1

1

1.To exclude a SharePoint Online site collection from the search results, use this PowerShell script:

enter code here
#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 = "https://XXXXX.sharepoint.com/sites/XXXXX"

#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
$Ctx.Load($Web)
$Ctx.ExecuteQuery()

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

2.Search box in SharePoint Online top navigation suite bar can be hidden with this PowerShell script:

$SiteURL = "https://XXXXX.sharepoint.com/sites/XXXXX"

#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
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()

    #Disable search in navigation bar
    $Web.SearchBoxInNavBar = 3
    $web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
1
  • Thank you Allen. I need to implement this code in Client Object model. Can you please guide me on this Commented Nov 26, 2020 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.