Script to mass disable sync for Office 365 Groups

Salvatore Biscari
Trusted Contributor

A customer of mine wants to disable sync for all Groups doclibs.

AFAIK there is not a global setting for this.

I know that it is possible to do it manually for every single doclib in the advanced library settings, but such approach is impractical for hundreds of Groups.

Can someone point me to an existing script for doing it for all Groups in a tenant?


cc @Juan Carlos González Martín @Santhosh Balakrishnan @Tony Redmond

30 Replies

I am sorry, but I do not know of any way to disable the ability for users to synchronize a document library via PowerShell...

Thank you, Tony.

You should be able to "temporary" hide the "sync" action in the Groups Library using CSOM (Client Side Object Model) in a PowerShell script...and I say "should" because in the past I have found some weird problems when using CSOM with Groups sites...but this should not be the case anymore since a Group site is a modern site. By the way, I have a script that hides the sync action for a document library in SPO using CSOM: https://gallery.technet.microsoft.com/How-to-enabledisable-sync-8ad53996?redir=0 (Bear in mind you will need to use at least August 2016 version of CSOM...I recommend you to use the once released by Microsoft yesterday (https://jcgonzalezmartin.wordpress.com/2017/01/28/office-365-january-version-of-spo-csom-just-releas... to get the CSOM assemblies via NuGet using PowerShell just follow this post: https://jcgonzalezmartin.wordpress.com/2017/01/09/tips-tricks-how-to-install-a-nuget-package-without...
Finally, you will need to buy the code to get the all the Groups sites in the tenant. You can use this post as a starting point : http://www.andrewjbillings.com/enumerating-sharepoint-sites-for-office-365-groups-with-powershell/
I've got something similar to this running (iterating content in Groups)

I've also upgrade to the latest CSOM assemblies, but I don't see the parameter exposed in the Group sites/libraries (i think it is ExcludeFromOfflineClient).
Small update from my side...Groups Sites and Office 365 Channel Sites are not hidden anymore when using Get-SPOSite, so you can choose to use Get-SPOSite or Groups cmdlets (probably better to use these ones)

Looks like it was still reading from my older version of CSOM, but got it working quick and dirty:


Add-Type -Path "C:\SP\Microsoft.SharePointOnline.CSOM.16.1.6112.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\SP\Microsoft.SharePointOnline.CSOM.16.1.6112.1200\lib\net45\Microsoft.SharePoint.Client.runtime.dll"

# SharePoint Authentication
$username = "<username here>"
$password = '<password here>'
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 

Write-Host "Fetching O365 Groups" -ForegroundColor Yellow
$o365Groups = get-unifiedgroup
$count = 0

foreach($group in $o365Groups){
    Write-Host ""
    Write-Host $count $group.DisplayName $group.primarysmtpaddress -ForegroundColor Cyan

    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($group.SharePointSiteUrl) 
    $clientContext.Credentials = $credentials 

    if ($clientContext.ServerObjectIsNull.Value) { 
        Write-Host "Unable to connect to: '$url'" -ForegroundColor Red
    } else {
        Write-Host "Connected to: '$($group.SharePointSiteUrl)'" -ForegroundColor Green 

        $Libraries = $clientContext.Web.Lists

        foreach($Library in $Libraries){
            if($Library.BaseTemplate -eq "101"){
                Write-Host $Library.Title



Thank you very much @Juan Carlos González Martín @Brent Ellis !!!

I have a couple of questions:

  • @Juan Carlos González Martín: why do you say "temporarily"? Do you mean that the setting can in any moment be changed by a Group owner?
  • @Brent Ellis: the script disables sync for all the doclibs in a Group, not only the main one, correct?
  • What happens to the syncs already running? Will they be disabled or will they continue to run?


Testing the script, I noticed that it sets "ExcludeFromOfflineClient=$true" not only on the main doclib of the Group, but also on other libraries (in Italian, the typical libraries affected are: Documenti, Modelli di modulo, Raccolta stili, Risorse del sito).

Does this have adverse consequences?

How to restrict the script only to actual doclibs?


I just assumed you wanted sync disabled across the board. The script gets any predefined doc libs, but also any other extra libraries that are created in the Group SharePoint site. You can add an extra "if" statement to limit it to a specific Library

if($Library.BaseTemplate -eq "101" -and $Library.Title -eq "Documents"){

Substitute "Documents" for whatever language phrase the main document library is. Not sure if it can be renamed in the group, so worse case might have to check the Library URL to make sure it is Shared%20Documents.

Thanks Brent.

The best would be to disable sync for all actual doclibs (i.e. the main one and any other doclibs created by the users) but not for other "system" libraries.

Unfortunately it looks like the condition $Library.BaseTemplate -eq "101" captures other "system" libraries as well (precisely, in Italian: Modelli di modulo, Raccolta stili, Risorse del sito).

I wonder if flipping ExcludeFromOfflineClient also for such "system" libraries (which appear to have $Library.BaseTemplate -eq "101") could have adverse side effects ?

What you could do is read the name of the document libraries you want to configure from a CSV file...and yes, I meant that a Group owner can configure the setting on

Thanks Juan!

And, after disabling, what happens to the local syncs already configured in the various machines?

Will they be automagically disabled (and in this case what will happen to the local file copies?) or will they continue to work?

In other words, does the setting purely hide the sync button in the web UI, or does it influence the behaviour of the OneDrive clients on the various machines?

Yes...this setting purely hide the sync button in the Web UI and does not have any influence on the OneDrive clients...so if users have already synchronized the Groups libraries, you will have to look for a way to disabling this synchronization

Forgive this non-SPO person asking a question, but I would like to summarize what has been discussed here.


  1. You can disable the Sync option that appears in the commands available within a document library.
  2. Disabling the Sync option does not stop the OneDrive client synchronizing data if the synchronization was already set up and active.
  3. The scripts to do the work depend on the SharePoint CSOM (i.e. you can't just run Set-SPOSite or Set-UnifiedGroup to set a property - which would be nice).
  4. Care needs to be taken to ensure that only the desired document libraries (those associated with Groups) are affected.
  5. Two example scripts are available - one from Juan Carlos and the other from Brent. Normal health practices to be observed (always test and never run in production until you are 100% happy that code downloaded from the internet is secure and does what you expect). 

Did I get that right?

@Tony Redmond

My two cents:

  1. Correct. You can do it manually in the UI, library by library. Or by a script.
  2. IMHO correct.
  3. IMHO correct.
  4. Correct. My concern is that the condition $Library.BaseTemplate -eq "101" in Brent's script captures (hence setting ExcludeFromOfflineClient=$true) also other "system" libraries and not only the (possibly multiple) "user" document libraries in each Group. Is it safe doing so?
  5. IMHO correct. (e.g. point 4 should be evaluated carefully).

Library.BaseTemplate = 101 specifies document libraries belonging to Office 365 Groups... Or all modern sites?


In the past, Groups used a special Group#0 template for its sites. Is that the same now (in an airplane with limited wi-fi so don't want to go through the slowwwwwww network check...) Maybe someone knows offhand.

Sorry guys for not joining on time to the party :-)...here my comments:
- 101 is the template ID for any document librarie in SharePoint (no matter if we talk about SharePoint OnPremises or Online, Modern Team Sites or Classic ones, or Groups sites)

- GROUPS#0 identifies the site template used for a Group site...but in a site you can create Document Libraries and lists and for them you have a template ID: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx

In regards of Tony's questions:
1. Correct
2. Correct (hiding the Sync option is just a cosmetic customization)
3. Correct
4. Correct
5. Of course :-)

Ta. Like everywhere in Office 365, if you take your eyes off the ball for a few minutes, things might change...


Good to know about the identifiers for document libraries. I like factoids like that!

Nevertheless, my question still remains unanswered...

I will try to be more clear.


We know the following facts:

  1. In every Group we have a main "user" document library (with template ID 101). In Italian it is called: Documenti.
  2. In every Group we also have what I would call "system" document libraries (with template ID 101). In Italian they are called: Modelli di modulo, Raccolta stili, Risorse del sito.
  3. In every Group we can create other "user" document libraries (with template ID 101).


All this said, if we want to hide the sync button in all "user" libraries by means of a script, and we select the libraries on the basis of template ID 101, we will (try to) hide the sync button also in the "system" document libraries (point 2) and not only in the "user" document libraries (point 1 and point 3).

My question is: is this safe?


(Of course in the script I can select the "user" document libraries "by name", but while this is easily feasible for the "main" one (point 1 above), it is instead difficult for the others (point 3 above))...

I guess I need more context. I do not think that the "system" document libraries are used by Office 365 Groups - unless someone can shed more light on this topic. If that is the case, then it might not be important if synchronization was disabled for these libraries. Do users ever synchronize them anyway?

My feeling is that it is not important if synchronization is disabled for these "system" libraries (and anyway users never synchronize them, I think), but I would like to have an "authoritative" answer... :smileyvery-happy:

I can't think of why a user would want or attempt to synchronize these libraries...


:-) Users some times want to do unexpected things...@Salvatore if the template ID approach does not work for you, use the document library name instead and read the document libraries names for every group form a CSV you have created beforehand

Should that comment be "users sometimes do silly things"?


Never mind...

Hi Juan,


I have read the posts here a few times, but are still not sure that this will solve what i am trying to do.


I am basicly looking for a scriptet solution that does the same as opening site settings for a single SPO site or O365 group, going into "Search and offline availability" and select no to "Specify whether this site should be available for offline clients".


Can i use your Csom script for this ?

The scripts discussed here are for document libraries. For the setting you want to disable (basically you want to mark a site as not searchable) you need a script (I don't recall If I have one for this scenario that uses CSOM) that does this at the site level

I took a stab at this using the scripts already created by @Juan Carlos González Martín and @Brent Ellis along with the site iteration scripts here.  This will set the Offline Client Availability at the web level initially for the site you enter and give you the option to do all subsites (I edited the original to include all levels of subsites based on this super handy script here and not just level 1).  I tested this on Group and Classic sites.  It certainly could be cleaned up a bit and be enhanced to support things like .csv input and probably overall more optimized.  

Add-Type -Path "C:\temp\microsoft.sharepointonline.csom.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\temp\microsoft.sharepointonline.csom.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.runtime.dll"

$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? (Y/N)"

# Generate ClientContext 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

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

    $rootWeb = $ctx.Web

    # update root site
    Write-Host $rootWeb.Url "is being updated to exclude from offline clients"
    Write-Host "ExcludeFromOfflineClient is now" $rootWeb.ExcludeFromOfflineClient "for the site:" $rootWeb.Url -ForegroundColor Green
    if ($subwebcheck -eq "Y") {
        # work with subsites
        Write-Host "Processing subsites..." -ForegroundColor Yellow
        $childWebs = $rootWeb.Webs
        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

        # perform update
        if($rootWeb.WebTemplate -ne "APP"){
            Write-Host $rootWeb.Url "is being updated to exclude from offline clients"
            Write-Host "ExcludeFromOfflineClient is now" $rootWeb.ExcludeFromOfflineClient "for the site:" $rootWeb.Url -ForegroundColor Green

        # loop subsites of subsites
        foreach ($childWeb in $childWebs)
            processsubsites $childWeb.url


To note, Setting this property to true does not disable synchronization. Instead, it represents a recommendation to the client not to attempt synchronization. This info is pulled from here


Thankyou so much Drew. This was spot on what i was looking for. Saved my day. Again, thanks a lot.

this script works very well for existing groups. But is it also possible to disable syncronization when creating a group? Otherwise you always have to switch something off afterwards

Related Conversations
Site design and Taxonomy fields
m t in SharePoint Developer on
1 Replies
Add new SPWeb with Sitescript?
isabasu in SharePoint Developer on
2 Replies
Apply site script to existing site?
Myles Gallagher in SharePoint on
2 Replies
Site themes via Rest.
SpeedyDevvy in SharePoint Developer on
3 Replies