Script to mass disable sync for Office 365 Groups

Silver 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?

TIA.

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){
    $count++
    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
        $clientContext.Load($Libraries)
        $clientContext.ExecuteQuery()

        foreach($Library in $Libraries){
            if($Library.BaseTemplate -eq "101"){
                Write-Host $Library.Title
                $Library.ExcludeFromOfflineClient=$true
                $Library.Update()
            }
        }

    }

}


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?

TIA

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!