Forum Discussion
Script to mass disable sync for Office 365 Groups
Thank you, Tony.
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/
- Jan 28, 2017Small 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)
- Michael PedersenFeb 05, 2017Copper Contributor
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 ?
- Feb 06, 2017
I took a stab at this using the scripts already created by jcgonzalezmartin 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 $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 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 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 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.
- Brent EllisJan 28, 2017Silver ContributorI'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).- Jan 28, 2017Brent, 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 EllisJan 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() } } } }