Forum Discussion
Salvatore Biscari
Jan 28, 2017Silver Contributor
Script to mass disable sync for Office 365 Groups
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 l...
Jan 28, 2017
Brent, check my script...It works and I used December edition of the CSOM (https://jcgonzalezmartin.wordpress.com/2017/01/19/office-365-how-to-disable-files-synchronization-in-spo-doc-libraries-ii/)
Brent Ellis
Jan 29, 2017Silver Contributor
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() } } } }
- Gijs BeldmanNov 17, 2017Copper Contributor
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
- Salvatore BiscariJan 29, 2017Silver Contributor
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?
- Brent EllisJan 29, 2017Silver ContributorI 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.- Salvatore BiscariJan 29, 2017Silver Contributor
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 ?
- Salvatore BiscariJan 29, 2017Silver Contributor
Thank you very much jcgonzalezmartin Brent Ellis !!!
I have a couple of questions:
- jcgonzalezmartin: 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