Forum Discussion
Aug 24, 2016
Timezone setting in ODFB
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 tim...
SanthoshB1
Aug 26, 2016Bronze Contributor
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
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++ }