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.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
}