Browse Tag

Sync

Hide Sync for Sites via PowerShell in SharePoint Online – Offline Client Availablity

Offline Client Availability is built within SharePoint to “Prevent users from downloading content from a site” via MS support.   There is not a way that I am aware of to fully stop existing syncs, but what is capable is to hide the Sync option from the views within the document library.  This setting can be done at the site and the library level.  

When working at the site level, this setting actually exists at the “Web” level within SharePoint.  This means its not a site collection level and needs to be set per site, including all subsites. 


What it looks like when done

This is what you will see with this setting set to NO:

Modern experience (no sync option)

Classic experience (sync option greyed out)


This is what you see with this setting set to YES:

Modern experience

Classic experience


Setting via Browser

The Offline Client Availability option can be set by single site under…

  1. On the site, click Settings > Site Settings.
  2. Under Search, click Search and offline availability.
  3. In the Offline Client Availability section, select No.


 

Setting via PowerShell powershell2

There was a good discussion going on within the MS Tech Community site around the ability to restrict sync via scripting and I tried to put together what I could to support it.  Obviously it would be tedious to try to set that for all sites and subsites across your tenant.  This was my first published attempt for CSOM so I used some great references to get me through it and this is probably rough around the edges.  All feedback is helpful!

Setting this CSOM web property (ExcludeFromOfflineClient) to true does not disable synchronization. Instead, it represents a recommendation to the client not to attempt synchronization via technet.

Ensure that you update the <script path> section near the header with the path to your CSOM files. Ensure you have at least the August 2016 version of CSOM.  Link to latest Nuget for download.

Link to download most recent version of powershell script from TechNet gallery

16235-illustration-of-a-green-download-button-pv

# Substitute your path to CSOM files (i.e. c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path "<insert path>\Microsoft.SharePoint.Client.dll"
Add-Type -Path "<insert path>\Microsoft.SharePoint.Client.runtime.dll"

# Variables with prompts
$siteUrl = Read-Host -Prompt "Enter Site Collection URL"
$username = Read-Host -Prompt “Enter username”
$password = Read-Host -Prompt “Enter password” -AsSecureString
$subwebcheck = Read-Host -Prompt "Do you want to process subsites? (enter 'Y' if yes)"

# Generate ClientContext(ctx) function so we can reuse
function GetClientContext($siteurl, $username, $password) {
 $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl) 
 $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) 
 $ctx.Credentials = $credentials
 return $ctx
}

$ctx = GetClientContext $siteurl $username $password

# Verify connection
if ($ctx.ServerObjectIsNull.Value) { 
 Write-Host "Unable to connect to: '$siteUrl'" -ForegroundColor Red
} else {
 Write-Host "Connected to: '$($siteUrl)'" -ForegroundColor Green 

 $rootWeb = $ctx.Web
 $ctx.Load($rootWeb)
 $ctx.ExecuteQuery()

 # Update root site
 Write-Host $rootWeb.Url "is being updated to exclude from offline clients"
 $rootWeb.ExcludeFromOfflineClient=$true
 $rootWeb.Update()
 $ctx.Load($rootWeb)
 $ctx.ExecuteQuery()
 Write-Host "ExcludeFromOfflineClient is now" $rootWeb.ExcludeFromOfflineClient "for the site:" $rootWeb.Url -ForegroundColor Green
 
 if ($subwebcheck -eq "Y") {
 
 # Work with all subsites
 Write-Host "Processing subsites..." -ForegroundColor Yellow
 $childWebs = $rootWeb.Webs
 $ctx.Load($childWebs)
 $ctx.ExecuteQuery()
 foreach ($childWeb in $childWebs)
 {
 processsubsites $childWeb.url
 }
 }

 # Function to loop through subsites and setting values
 function processsubsites ($siteurl){
 $ctx = GetClientContext $siteurl $username $password
 $rootWeb = $ctx.Web
 $childWebs = $rootWeb.Webs
 $ctx.Load($rootWeb)
 $ctx.Load($childWebs)
 $ctx.ExecuteQuery()

 # Perform update for all template types except APPs to exclude from offline clients
 if($rootWeb.WebTemplate -ne "APP"){
 Write-Host $rootWeb.Url "is being updated to exclude from offline clients"
 $rootWeb.ExcludeFromOfflineClient=$true
 $rootWeb.Update()
 $ctx.Load($rootWeb)
 $ctx.ExecuteQuery()
 Write-Host "ExcludeFromOfflineClient is now" $rootWeb.ExcludeFromOfflineClient "for the site:" $rootWeb.Url -ForegroundColor Green
 }

 # Loop subsites of subsites of subsites...etc
 foreach ($childWeb in $childWebs)
 { 
 processsubsites $childWeb.url
 }
 }
}

Used helpful references 

So much good info already out there that helped me get started; Thank you!