1

We have a company web application that is divided into multiple site collections though the average user only sees this as a single "website" because they are linked with a single global navigation. Some of the users are in branch offices with different time zones and we need to take this into account for things like calendars. As I understand it we would have to have the user go into every single site collection and change their regional settings to the correct time zone for their branch office.

This obviously not something that should be asked of the users so is there instead a more efficient way of doing this using code? What is the best way to keep these settings synchronized so that changing the timezone in one site collection will change it in all others under the same web application?

0

http://www.eblogin.com/eblogin/post/2012/04/11/sp-changeUserTimezone.aspx for programmatically setting regional settings.

Working on finding how to capture the event for the setting change... or at least some alternative that makes sense.

0

I found a solution that bypasses the standard user method of setting time zones themselves. I have the user profile synchronization service importing information like "Office" for each user so I use that value to determine the user's time zone. I have a scheduled task that runs nightly and calls a batch file that calls a PowerShell file that iterates through the site collections in my web app and it sets the time zone based on the "Office" field.

Here is a link to the list of SharePoint time zones with ids: http://johnlivingstontech.blogspot.com/2011/01/sharepoint-spregionalsettingsglobaltime.html

Here is the script:

$webApplication = Get-SPWebApplication $webApplicationUrlHome
$centralAdmin = Get-SPSite $centralAdminUrl
$serverContext = Get-SPServiceContext $centralAdmin
$userProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serverContext)

$webApplication.Sites | ForEach-Object {

    $web = $_.RootWeb
    $userInformationList = $_.RootWeb.Lists["User Information List"]

    $userProfileManager.GetEnumerator() | ForEach-Object {
        $accountName = $_["AccountName"][0]
        $office = $_["Office"][0]
        $matchingUser_Method1 = Get-SPUser -Web $web.Url -Identity $accountName -ERRORACTION SilentlyContinue

        if($matchingUser_Method1 -ne $null)
        {
            if($office -eq "Office Location 1")
            {
                $newTimeZoneId = 11
            }
            elseif($office -eq "Office Location 2")
            {
                $newTimeZoneId = 10
            }
            elseif($office -eq "Office Location 3")
            {
                $newTimeZoneId = 38
            }
            elseif($office -eq "Office Location 4")
            {
                $newTimeZoneId = 13
            }
            else
            {
                $newTimeZoneId = 11
            }

            $regionalSettings = new-object Microsoft.SharePoint.SPRegionalSettings($web, $true)
            $regionalSettings.TimeZone.Id = $newTimeZoneId

            $matchingUser_Method1.RegionalSettings = $regionalSettings
            $matchingUser_Method1.Update()
        }

        $matchingUser_Method2 = $userInformationList.Items | Where-Object { 
            $accountName.CompareTo($_["Account"].ToString()) -eq 0 
        }

        if($matchingUser_Method2 -ne $null)
        {
            if($office -eq "Office Location 1")
            {
                $newTimeZoneId = 11
            }
            elseif($office -eq "Office Location 2")
            {
                $newTimeZoneId = 10
            }
            elseif($office -eq "Office Location 3")
            {
                $newTimeZoneId = 38
            }
            elseif($office -eq "Office Location 4")
            {
                $newTimeZoneId = 13
            }
            else
            {
                $newTimeZoneId = 11
            }

            $matchingUser_Method2["TimeZone"] = $newTimeZoneId
            $matchingUser_Method2.Update()
        }
    }

    $_.RootWeb.Dispose()
    $_.Dispose()
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.