Timezone setting in ODFB

%3CLINGO-SUB%20id%3D%22lingo-sub-7091%22%20slang%3D%22en-US%22%3ETimezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-7091%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20know%20that%20the%20timezone%20in%20OneDrive%20for%20Business%20is%20set%20uniquely%20for%20each%20user%20much%20like%20any%20other%20SharePoint%20site%20collection%20or%20site%20for%20that%20matter.%3C%2FP%3E%3CP%3EInstead%20of%20relying%20on%20the%20user%20to%20set%20the%20timezone%20themselves%20-%20are%20there%20any%20other%20ways%20to%20set%20the%20timezone%3F%20Does%20it%20potentially%20feed%20from%20OWA%20when%20the%20user%20first%20logs%20in%20and%20sets%20their%20timezone%20there%3F%3C%2FP%3E%3CP%3EOr%20can%20we%20do%20something%20via%20PowerShell%20or%20programmatically%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20struggling%20to%20find%20any%20documentation%20on%20this%20specifically.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-42054%22%20slang%3D%22en-US%22%3ERe%3A%20Timezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-42054%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20this%20-%20I've%20used%20this%20post%20to%20create%20a%20couple%20scripts%20to%20update%20the%20entire%20site%20and%20also%20on%20individual%20sites%20in%20a%20CSV.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20I%20can't%20figure%20out%20how%20to%20get%20the%20current%20timezone%20properties%20associated%20to%20a%20user's%20ODFB.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20a%20straight-forward%20ask%2C%20but%20is%20it%20possible%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-7658%22%20slang%3D%22en-US%22%3ERe%3A%20Timezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-7658%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20you%20need%20to%20set%20domain%20admin%26nbsp%3Bas%20the%20Secondary%20admin%20for%20OD4B.%20Now%20you%20have%20permission%20to%20set%20timezone%20for%20the%20user.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EStep%201%3A%3C%2FSTRONG%3E%20Script%20to%20set%20Secondary%20Admin%20for%20OD4B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EStep%202%3C%2FSTRONG%3E%3A%20Now%20use%20the%20below%20script%20to%20set%20the%20timezone%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%23%20Specify%20your%20organization%20admin%20central%20url%0A%24AdminURI%20%3D%20%22https%3A%2F%2F%26lt%3Bdomianname%26gt%3B-admin.sharepoint.com%22%0A%23%20Specify%20the%20User%20account%20for%20an%20Office%20365%20global%20admin%20in%20your%20organization%0A%24AdminAccount%20%3D%20%22admin%40%26lt%3Bdomianname%26gt%3B.onmicrosoft.com%22%0A%24AdminPass%20%3D%20%22pass%40word1%22%0A%24TimezoneValue%3D%20%22(UTC%2B05%3A30)%20Chennai%2C%20Kolkata%2C%20Mumbai%2C%20New%20Delhi%22%0A%26nbsp%3B%0A%23%20Specify%20the%20secondary%20admin%20account%20and%20the%20url%20for%20the%20onedrive%20site%0A%24siteURI%20%3D%20%22https%3A%2F%2F%26lt%3Bdomianname%26gt%3B-my.sharepoint.com%22%0A%26nbsp%3B%0A%24loadInfo1%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client%22)%0A%24loadInfo2%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.Runtime%22)%0A%24loadInfo3%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.UserProfiles%22)%0A%26nbsp%3B%0A%24sstr%20%3D%20ConvertTo-SecureString%20-string%20%24AdminPass%20-AsPlainText%20-Force%0A%23%24AdminPass%20%3D%20%22%22%0A%24creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24AdminAccount%2C%20%24sstr)%0A%24UserCredential%20%3D%20New-Object%20System.Management.Automation.PSCredential%20-argumentlist%20%24AdminAccount%2C%20%24sstr%0A%26nbsp%3B%0A%23%20Add%20the%20path%20of%20the%20User%20Profile%20Service%20to%20the%20SPO%20admin%20URL%2C%20then%20create%20a%20new%20webservice%20proxy%20to%20access%20it%0A%24proxyaddr%20%3D%20%22%24AdminURI%2F_vti_bin%2FUserProfileService.asmx%3Fwsdl%22%0A%24UserProfileService%3D%20New-WebServiceProxy%20-Uri%20%24proxyaddr%20-UseDefaultCredential%20False%0A%24UserProfileService.Credentials%20%3D%20%24creds%0A%26nbsp%3B%0A%23%20Set%20variables%20for%20authentication%20cookies%0A%24strAuthCookie%20%3D%20%24creds.GetAuthenticationCookie(%24AdminURI)%0A%24uri%20%3D%20New-Object%20System.Uri(%24AdminURI)%0A%24container%20%3D%20New-Object%20System.Net.CookieContainer%0A%24container.SetCookies(%24uri%2C%20%24strAuthCookie)%0A%24UserProfileService.CookieContainer%20%3D%20%24container%0A%26nbsp%3B%0A%23%20Sets%20the%20first%20User%20profile%2C%20at%20index%20-1%0A%24UserProfileResult%20%3D%20%24UserProfileService.GetUserProfileByIndex(-1)%0AWrite-Host%20%22Starting-%20This%20could%20take%20a%20while.%22%0A%24NumProfiles%20%3D%20%24UserProfileService.GetUserProfileCount()%0A%24i%20%3D%201%0A%26nbsp%3B%0AConnect-SPOService%20-Url%20%24AdminURI%20-Credential%20%24UserCredential%0A%26nbsp%3B%0A%23%20As%20long%20as%20the%20next%20User%20profile%20is%20NOT%20the%20one%20we%20started%20with%20(at%20-1)...%0AWhile%20(%24UserProfileResult.NextValue%20-ne%20-1)%0A%7B%0AWrite-Host%20%22Examining%20profile%20%24i%20of%20%24NumProfiles%22%0A%23%20Look%20for%20the%20Personal%20Space%20object%20in%20the%20User%20Profile%20and%20retrieve%20it%0A%23%20(PersonalSpace%20is%20the%20name%20of%20the%20path%20to%20a%20user's%20OneDrive%20for%20Business%20site.%20Users%20who%20have%20not%20yet%20created%20a%26nbsp%3B%0A%23%20OneDrive%20for%20Business%20site%20might%20not%20have%20this%20property%20set.)%0A%24Prop%20%3D%20%24UserProfileResult.UserProfile%20%7C%20Where-Object%20%7B%20%24_.Name%20-eq%20%22PersonalSpace%22%20%7D%0A%24Url%3D%20%24Prop.Values%5B0%5D.Value%0A%26nbsp%3B%0A%23%20If%20OneDrive%20is%20activated%20for%20the%20user%2C%20then%20set%20the%20secondary%20admin%0Aif%20(%24Url)%20%7B%0A%24sitename%20%3D%20%24siteURI%20%2B%20%24Url%0A%24Site%20%3D%20%24sitename%0A%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24Site)%0A%24Context.Credentials%20%3D%20%24Creds%0A%24TimeZones%20%3D%20%24Context.Web.RegionalSettings.TimeZones%0A%24Context.Load(%24TimeZones)%0A%24Context.ExecuteQuery()%0A%24RegionalSettings%20%3D%20%24Context.Web.RegionalSettings%0A%24Context.Load(%24RegionalSettings)%0A%24Context.ExecuteQuery()%0A%24TimeZone%20%3D%20%24TimeZones%20%7C%20Where%20%7B%24_.Description%20-eq%20%24TimezoneValue%7D%0A%24RegionalSettings.TimeZone%20%3D%20%24TimeZone%0A%24Context.Web.Update()%0A%24Context.ExecuteQuery()%0AWrite-Host%20%22Time%20Zone%20successfully%20updated%20for%20%24(%24site)%20%22%0A%26nbsp%3B%0A%7D%0A%26nbsp%3B%0A%23%20And%20now%20we%20check%20the%20next%20profile%20the%20same%20way...%0A%24UserProfileResult%20%3D%20%24UserProfileService.GetUserProfileByIndex(%24UserProfileResult.NextValue)%0A%24i%2B%2B%0A%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-7657%22%20slang%3D%22en-US%22%3ERe%3A%20Timezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-7657%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20you%20need%20to%20set%20domain%20admin%26nbsp%3Bas%20the%20Secondary%20admin%20for%20OD4B.%20Now%20you%20have%20permission%20to%20set%20timezone%20for%20the%20user.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EStep%201%3A%3C%2FSTRONG%3E%20Script%20to%20set%20Secondary%20Admin%20for%20OD4B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.jijitechnologies.com%2Fblogs%2Fadd-remove-secondary-site-collection-admin-to-all-onedrive-for-business-users%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EStep%202%3C%2FSTRONG%3E%3A%20Now%20use%20the%20below%20script%20to%20set%20the%20timezone%3C%2FP%3E%3CPRE%3E%23%20Specify%20your%20organization%20admin%20central%20url%0A%24AdminURI%20%3D%20%22https%3A%2F%2F%26lt%3Bdomianname%26gt%3B-admin.sharepoint.com%22%0A%23%20Specify%20the%20User%20account%20for%20an%20Office%20365%20global%20admin%20in%20your%20organization%0A%24AdminAccount%20%3D%20%22admin%40%26lt%3Bdomianname%26gt%3B.onmicrosoft.com%22%0A%24AdminPass%20%3D%20%22pass%40word1%22%0A%24TimezoneValue%3D%20%22(UTC%2B05%3A30)%20Chennai%2C%20Kolkata%2C%20Mumbai%2C%20New%20Delhi%22%0A%26nbsp%3B%0A%23%20Specify%20the%20secondary%20admin%20account%20and%20the%20url%20for%20the%20onedrive%20site%0A%24siteURI%20%3D%20%22https%3A%2F%2F%26lt%3Bdomianname%26gt%3B-my.sharepoint.com%22%0A%26nbsp%3B%0A%24loadInfo1%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client%22)%0A%24loadInfo2%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.Runtime%22)%0A%24loadInfo3%20%3D%20%5BSystem.Reflection.Assembly%5D%3A%3ALoadWithPartialName(%22Microsoft.SharePoint.Client.UserProfiles%22)%0A%26nbsp%3B%0A%24sstr%20%3D%20ConvertTo-SecureString%20-string%20%24AdminPass%20-AsPlainText%20-Force%0A%23%24AdminPass%20%3D%20%22%22%0A%24creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24AdminAccount%2C%20%24sstr)%0A%24UserCredential%20%3D%20New-Object%20System.Management.Automation.PSCredential%20-argumentlist%20%24AdminAccount%2C%20%24sstr%0A%26nbsp%3B%0A%23%20Add%20the%20path%20of%20the%20User%20Profile%20Service%20to%20the%20SPO%20admin%20URL%2C%20then%20create%20a%20new%20webservice%20proxy%20to%20access%20it%0A%24proxyaddr%20%3D%20%22%24AdminURI%2F_vti_bin%2FUserProfileService.asmx%3Fwsdl%22%0A%24UserProfileService%3D%20New-WebServiceProxy%20-Uri%20%24proxyaddr%20-UseDefaultCredential%20False%0A%24UserProfileService.Credentials%20%3D%20%24creds%0A%26nbsp%3B%0A%23%20Set%20variables%20for%20authentication%20cookies%0A%24strAuthCookie%20%3D%20%24creds.GetAuthenticationCookie(%24AdminURI)%0A%24uri%20%3D%20New-Object%20System.Uri(%24AdminURI)%0A%24container%20%3D%20New-Object%20System.Net.CookieContainer%0A%24container.SetCookies(%24uri%2C%20%24strAuthCookie)%0A%24UserProfileService.CookieContainer%20%3D%20%24container%0A%26nbsp%3B%0A%23%20Sets%20the%20first%20User%20profile%2C%20at%20index%20-1%0A%24UserProfileResult%20%3D%20%24UserProfileService.GetUserProfileByIndex(-1)%0AWrite-Host%20%22Starting-%20This%20could%20take%20a%20while.%22%0A%24NumProfiles%20%3D%20%24UserProfileService.GetUserProfileCount()%0A%24i%20%3D%201%0A%26nbsp%3B%0AConnect-SPOService%20-Url%20%24AdminURI%20-Credential%20%24UserCredential%0A%26nbsp%3B%0A%23%20As%20long%20as%20the%20next%20User%20profile%20is%20NOT%20the%20one%20we%20started%20with%20(at%20-1)...%0AWhile%20(%24UserProfileResult.NextValue%20-ne%20-1)%0A%7B%0AWrite-Host%20%22Examining%20profile%20%24i%20of%20%24NumProfiles%22%0A%23%20Look%20for%20the%20Personal%20Space%20object%20in%20the%20User%20Profile%20and%20retrieve%20it%0A%23%20(PersonalSpace%20is%20the%20name%20of%20the%20path%20to%20a%20user's%20OneDrive%20for%20Business%20site.%20Users%20who%20have%20not%20yet%20created%20a%26nbsp%3B%0A%23%20OneDrive%20for%20Business%20site%20might%20not%20have%20this%20property%20set.)%0A%24Prop%20%3D%20%24UserProfileResult.UserProfile%20%7C%20Where-Object%20%7B%20%24_.Name%20-eq%20%22PersonalSpace%22%20%7D%0A%24Url%3D%20%24Prop.Values%5B0%5D.Value%0A%26nbsp%3B%0A%23%20If%20OneDrive%20is%20activated%20for%20the%20user%2C%20then%20set%20the%20secondary%20admin%0Aif%20(%24Url)%20%7B%0A%24sitename%20%3D%20%24siteURI%20%2B%20%24Url%0A%24Site%20%3D%20%24sitename%0A%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24Site)%0A%24Context.Credentials%20%3D%20%24Creds%0A%24TimeZones%20%3D%20%24Context.Web.RegionalSettings.TimeZones%0A%24Context.Load(%24TimeZones)%0A%24Context.ExecuteQuery()%0A%24RegionalSettings%20%3D%20%24Context.Web.RegionalSettings%0A%24Context.Load(%24RegionalSettings)%0A%24Context.ExecuteQuery()%0A%24TimeZone%20%3D%20%24TimeZones%20%7C%20Where%20%7B%24_.Description%20-eq%20%24TimezoneValue%7D%0A%24RegionalSettings.TimeZone%20%3D%20%24TimeZone%0A%24Context.Web.Update()%0A%24Context.ExecuteQuery()%0AWrite-Host%20%22Time%20Zone%20successfully%20updated%20for%20%24(%24site)%20%22%0A%26nbsp%3B%0A%7D%0A%26nbsp%3B%0A%23%20And%20now%20we%20check%20the%20next%20profile%20the%20same%20way...%0A%24UserProfileResult%20%3D%20%24UserProfileService.GetUserProfileByIndex(%24UserProfileResult.NextValue)%0A%24i%2B%2B%0A%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-7174%22%20slang%3D%22en-US%22%3ERe%3A%20Timezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-7174%22%20slang%3D%22en-US%22%3E%3CP%3EFrom%20what%20i%C2%B4ve%20heard%20the%20time%20zone%20for%20a%20ODFB%20or%20Personal%20site%20is%20set%20from%20the%20My%20Site%20Host.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20from%20what%20ive%20experienced%2C%20there%20is%20no%20way%20to%20change%20the%20default%20time%20zone%20after%20the%20fact%2C%20if%20you%20dont%20want%20to%20run%20CSOM%20to%20change%20new%20ODFBs%20timezones.%3C%2FP%3E%3CP%3EThis%20is%20a%20huge%20issue%20for%20my%20swedish%20organisation%20where%20a%20previous%20administrator%20set%20up%20Sharepoint%20Online%20with%20american%20timezones.%20..%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20i%20guess%20i%20also%20would%20like%20some%20documentation%2C%20clarification%20on%20the%20topic.%3C%2FP%3E%3CP%3EHow%20is%20the%20timezone%20set%3F%3C%2FP%3E%3CP%3ECan%20you%20change%20default%20time%20zone%3F%3C%2FP%3E%3CP%3ECan%20you%20bulk%20change%20time%20zone%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-7168%22%20slang%3D%22en-US%22%3ERE%3A%20Timezone%20setting%20in%20ODFB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-7168%22%20slang%3D%22en-US%22%3EYou%20could%20write%20some%20code%20(C%23%20or%20PowerShell)%20to%20do%20that%20job%20for%20you.%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted
You could write some code (C# or PowerShell) to do that job for you.
Highlighted

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?

Highlighted

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++
}

 

Highlighted

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++
}

 

 

Highlighted

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?