SharePoint Online: How to Disable "Sync" Button in Document Library?

Requirement: Disable Sync button in SharePoint Online or OneDrive for Business Document Library
sharepoint online disable document library sync

How to disable sync button in a Document Library?
To disable sync button for a single library,
  • Go to: Library Settings >> Advanced Settings 
  • Set "No" for "Offline Client Availability"
    sharepoint online disable document library sync
This disables Sync button from the library.


Disable sync in SharePoint Online Site:
If you want to disable sync for your entire site:
  • Go to Site Settings >> Click on "Search and Offline Availability" under "Search" group
  • Set "No" for "Offline Client Availability" setting
    sharepoint online hide sync button
This hides sync button from all libraries in SharePoint Online. Please note this settings is at "Site" level, not a site collection level and needs to be set on all site of the site collection, so lets use PowerShell!

PowerShell to Remove Sync Button in All Sites of the Site Collection
Lets hide sync button for a SharePoint Online Site Collection.
#Load SharePoint CSOM 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"

Function Disable-SPOSyncButton([String]$SiteURL)
{  
    Try{
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the Web and Sub Sites
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.Load($Web.Webs)
        $Ctx.ExecuteQuery()

        $Web.ExcludeFromOfflineClient=$true
        $Web.Update()
        $Ctx.ExecuteQuery()
        Write-Host -f Green "Sync Button is Disabled for the Site:" $($SiteURL)

        #Iterate through each subsite of the current web
        ForEach ($Subweb in $Ctx.Web.Webs)
        {
            #Call the function recursively 
            Disable-SPOSyncButton -SiteURL $Subweb.url
        }
    }
    Catch {
        write-host -f Red "Error Disabling Sync Button!" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Call the function 
Disable-SPOSyncButton -SiteURL $SiteURL
SharePoint Online: How to Disable "Sync" Button in Document Library? SharePoint Online: How to Disable "Sync" Button in Document Library? Reviewed by Salaudeen Rajack on August 16, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.