Forum Discussion
Andreas Schlüter
Nov 02, 2016Brass Contributor
Time Zone Settings for O365 Groups SharePoint-Site
Hi everybody, most of us know the different places where time zones are to set in O365 - SharePoint Sites, ODFB, Users, etc. This is a mess... I (Owner & Member) tried to set the time zone fo...
- Nov 02, 2016
You can use the below script for this.
To Get the time zone index values
https://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11).aspx
To get Locale ID
https://msdn.microsoft.com/en-us/library/ms912047(v=winembedded.10).aspx
$cred= Get-Credential $TimezoneValue= "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi"
$localeid = 5129 $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $Session #Add references to SharePoint client assemblies Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location) Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location) $Groups =Get-UnifiedGroup |Where-Object {$_.SharePointSiteUrl -ne $null}|select SharePointSiteUrl foreach($Group in $Groups.SharePointSiteUrl) { #Authenticate to Site $Username =$cred.UserName.ToString() $Password = $cred.GetNetworkCredential().Password $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force $Site = $Group $Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$SecurePassword) $Context.Credentials = $Creds $TimeZones = $Context.Web.RegionalSettings.TimeZones $Context.Load($TimeZones) $Context.ExecuteQuery() #Changing the timezone $RegionalSettings = $Context.Web.RegionalSettings $Context.Load($RegionalSettings) $Context.ExecuteQuery() $TimeZone = $TimeZones | Where {$_.Description -eq $TimezoneValue} $RegionalSettings.TimeZone = $TimeZone
$RegionalSettings.Localeid = $localeid $Context.Web.Update() $Context.ExecuteQuery() Write-Host "Time Zone successfully updated for $($site) " }
Apr 16, 2018
TonyRedmond I think site designs is now the better way to do this, here is how I set timezone by default on new sites
https://regarding365.com/set-the-default-region-and-timezone-for-microsoft-teams-sites-a3b4d98da8c1
You can also apply a sitedesign using powershell to an existing site using Invoke-SPOSite
TonyRedmond
Apr 16, 2018MVP
Yes, I know about site designs and am using one very successfully for new sites created by Groups and Teams (and will have an article about same on Petri.com soon after I get some other stuff done). The question is how to deal with old sites that still have the Pacific time zone. I'll look at the Invoke-SpoSiteDesign cmdlet. Maybe it will be more cooperative than CSOM.
- Oct 11, 2018Being a Global Admin that not provides you with the rights to change settings that only a SPO Site Admin can do...so to change the settings in all the groups you would need to be an admin there or ask an admin to execute your script
- Barry SilicOct 11, 2018Copper Contributor
Hi
All I would like to do is update the language for all Office365 groups.
when I try to use your script I get the below error.
the groups are private and I am a global admin
Any help would be great. thank you.
Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. You do not have permission to perform this
action or access this resource."
At line:18 char:1
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerUnauthorizedAccessException - Bernard WelmersAug 15, 2018Brass Contributor
Here is a tweak on the script that was shared to set the TimeZone on all sharepoint sites in a tenant. I think this works a bit quicker/better then just doing it for team sites, since all the communication sites need the timezone fixed as well.
(I tired to add this as a code block but the editor did not like it)
$cred = get-credential$TimezoneValue= "(UTC-06:00) Central Time (US and Canada)"$localeid = 1033Connect-SPOService -Url https://<<TenantName>>-admin.sharepoint.com -Credential $cred$Groups = Get-SPOSite | select URL#Authenticate to Site$Username =$cred.UserName.ToString()$Password = $cred.GetNetworkCredential().Password$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$SecurePassword)foreach($site in $Groups.URL){$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)$Context.Credentials = $Creds$TimeZones = $Context.Web.RegionalSettings.TimeZones$Context.Load($TimeZones)$Context.ExecuteQuery()$TimeZone = $TimeZones | Where {$_.Description -eq $TimezoneValue}#Changing the timezone$RegionalSettings = $Context.Web.RegionalSettings$Context.Load($RegionalSettings)$Context.ExecuteQuery()$RegionalSettings.TimeZone = $TimeZone$RegionalSettings.Localeid = $localeid$Context.Web.Update()$Context.ExecuteQuery()Write-Host "Time Zone successfully updated for $($site) "} - TonyRedmondApr 16, 2018MVP
The Invoke-SPOSiteDesign method works pretty well. At least, it updated 109 of my 142 groups. I don't quite know why the other sites failed to be updated because I ran the script using the Administrator (tenant global administrator) account, but c'est la vie.
Here's what I used:
$SitesUpdated = 0 $SiteProblems = 0 $DesignID = "11c2efae-d0eb-4eb9-af71-4f4f5c5c6db8" $Groups = (Get-UnifiedGroup | ? {$_.SharePointSiteUrl -ne $Null} | Select SharePointSiteUrl, DisplayName, Alias) ForEach ($G in $Groups) { Try { Write-Host "Processing" $G.SharePointSiteUrl "for group" $G.DisplayName Invoke-SPOSiteDesign -Identity $DesignID -WebUrl $G.SharePointSiteURL -ErrorAction Stop $SitesUpdated++ Set-UnifiedGroup -Identity $G.Alias -CustomAttribute13 "Site Design Updated" } Catch { Write-Host "Problem Processing" $G.SharePointSiteURL $SiteProblems++ } }