Timezone setting in ODFB

MVP

We know that the timezone in OneDrive for Business is set uniquely for each user much like any other SharePoint site collection or site for that matter.

Instead of relying on the user to set the timezone themselves - are there any other ways to set the timezone? Does it potentially feed from OWA when the user first logs in and sets their timezone there?

Or can we do something via PowerShell or programmatically?

 

I'm struggling to find any documentation on this specifically.

5 Replies
You could write some code (C# or PowerShell) to do that job for you.

From what i´ve heard the time zone for a ODFB or Personal site is set from the My Site Host.

 

And from what ive experienced, there is no way to change the default time zone after the fact, if you dont want to run CSOM to change new ODFBs timezones.

This is a huge issue for my swedish organisation where a previous administrator set up Sharepoint Online with american timezones. ..

 

So i guess i also would like some documentation, clarification on the topic.

How is the timezone set?

Can you change default time zone?

Can you bulk change time zone?

First you need to set domain admin as the Secondary admin for OD4B. Now you have permission to set timezone for the user. 

 

Step 1: Script to set Secondary Admin for OD4B

http://www.jijitechnologies.com/blogs/add-remove-secondary-site-collection-admin-to-all-onedrive-for...

 

Step 2: Now use the below script to set the timezone

# Specify your organization admin central url
$AdminURI = "https://<domianname>-admin.sharepoint.com"
# Specify the User account for an Office 365 global admin in your organization
$AdminAccount = "admin@<domianname>.onmicrosoft.com"
$AdminPass = "pass@word1"
$TimezoneValue= "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi"
 
# Specify the secondary admin account and the url for the onedrive site
$siteURI = "https://<domianname>-my.sharepoint.com"
 
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
 
$sstr = ConvertTo-SecureString -string $AdminPass -AsPlainText -Force
#$AdminPass = ""
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount, $sstr)
$UserCredential = New-Object System.Management.Automation.PSCredential -argumentlist $AdminAccount, $sstr
 
# Add the path of the User Profile Service to the SPO admin URL, then create a new webservice proxy to access it
$proxyaddr = "$AdminURI/_vti_bin/UserProfileService.asmx?wsdl"
$UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False
$UserProfileService.Credentials = $creds
 
# Set variables for authentication cookies
$strAuthCookie = $creds.GetAuthenticationCookie($AdminURI)
$uri = New-Object System.Uri($AdminURI)
$container = New-Object System.Net.CookieContainer
$container.SetCookies($uri, $strAuthCookie)
$UserProfileService.CookieContainer = $container
 
# Sets the first User profile, at index -1
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
Write-Host "Starting- This could take a while."
$NumProfiles = $UserProfileService.GetUserProfileCount()
$i = 1
 
Connect-SPOService -Url $AdminURI -Credential $UserCredential
 
# As long as the next User profile is NOT the one we started with (at -1)...
While ($UserProfileResult.NextValue -ne -1)
{
Write-Host "Examining profile $i of $NumProfiles"
# Look for the Personal Space object in the User Profile and retrieve it
# (PersonalSpace is the name of the path to a user's OneDrive for Business site. Users who have not yet created a 
# OneDrive for Business site might not have this property set.)
$Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" }
$Url= $Prop.Values[0].Value
 
# If OneDrive is activated for the user, then set the secondary admin
if ($Url) {
$sitename = $siteURI + $Url
$Site = $sitename
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Context.Credentials = $Creds
$TimeZones = $Context.Web.RegionalSettings.TimeZones
$Context.Load($TimeZones)
$Context.ExecuteQuery()
$RegionalSettings = $Context.Web.RegionalSettings
$Context.Load($RegionalSettings)
$Context.ExecuteQuery()
$TimeZone = $TimeZones | Where {$_.Description -eq $TimezoneValue}
$RegionalSettings.TimeZone = $TimeZone
$Context.Web.Update()
$Context.ExecuteQuery()
Write-Host "Time Zone successfully updated for $($site) "
 
}
 
# And now we check the next profile the same way...
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
$i++
}

 

First you need to set domain admin as the Secondary admin for OD4B. Now you have permission to set timezone for the user. 

 

Step 1: Script to set Secondary Admin for OD4B

http://www.jijitechnologies.com/blogs/add-remove-secondary-site-collection-admin-to-all-onedrive-for...

 

Step 2: Now use the below script to set the timezone

 

# Specify your organization admin central url
$AdminURI = "https://<domianname>-admin.sharepoint.com"
# Specify the User account for an Office 365 global admin in your organization
$AdminAccount = "admin@<domianname>.onmicrosoft.com"
$AdminPass = "pass@word1"
$TimezoneValue= "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi"
 
# Specify the secondary admin account and the url for the onedrive site
$siteURI = "https://<domianname>-my.sharepoint.com"
 
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")
 
$sstr = ConvertTo-SecureString -string $AdminPass -AsPlainText -Force
#$AdminPass = ""
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount, $sstr)
$UserCredential = New-Object System.Management.Automation.PSCredential -argumentlist $AdminAccount, $sstr
 
# Add the path of the User Profile Service to the SPO admin URL, then create a new webservice proxy to access it
$proxyaddr = "$AdminURI/_vti_bin/UserProfileService.asmx?wsdl"
$UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False
$UserProfileService.Credentials = $creds
 
# Set variables for authentication cookies
$strAuthCookie = $creds.GetAuthenticationCookie($AdminURI)
$uri = New-Object System.Uri($AdminURI)
$container = New-Object System.Net.CookieContainer
$container.SetCookies($uri, $strAuthCookie)
$UserProfileService.CookieContainer = $container
 
# Sets the first User profile, at index -1
$UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1)
Write-Host "Starting- This could take a while."
$NumProfiles = $UserProfileService.GetUserProfileCount()
$i = 1
 
Connect-SPOService -Url $AdminURI -Credential $UserCredential
 
# As long as the next User profile is NOT the one we started with (at -1)...
While ($UserProfileResult.NextValue -ne -1)
{
Write-Host "Examining profile $i of $NumProfiles"
# Look for the Personal Space object in the User Profile and retrieve it
# (PersonalSpace is the name of the path to a user's OneDrive for Business site. Users who have not yet created a 
# OneDrive for Business site might not have this property set.)
$Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "PersonalSpace" }
$Url= $Prop.Values[0].Value
 
# If OneDrive is activated for the user, then set the secondary admin
if ($Url) {
$sitename = $siteURI + $Url
$Site = $sitename
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Context.Credentials = $Creds
$TimeZones = $Context.Web.RegionalSettings.TimeZones
$Context.Load($TimeZones)
$Context.ExecuteQuery()
$RegionalSettings = $Context.Web.RegionalSettings
$Context.Load($RegionalSettings)
$Context.ExecuteQuery()
$TimeZone = $TimeZones | Where {$_.Description -eq $TimezoneValue}
$RegionalSettings.TimeZone = $TimeZone
$Context.Web.Update()
$Context.ExecuteQuery()
Write-Host "Time Zone successfully updated for $($site) "
 
}
 
# And now we check the next profile the same way...
$UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue)
$i++
}

 

 

Thanks for this - I've used this post to create a couple scripts to update the entire site and also on individual sites in a CSV.

 

However, I can't figure out how to get the current timezone properties associated to a user's ODFB.

 

It seems a straight-forward ask, but is it possible?