Updating TimeZone in SharePoint 2013 through Powershell

February 23, 2015

It happens. One of the settings in SharePoint gets overlooked. SharePoint has been up and running for over a year and no one really noticed that every new site was being created with a Pacific time zone, which is not good since we are in the Eastern time zone. It went unnoticed until one engineer realized that the document he just posted reported a submit-time of three hours earlier. A quick fix to the site collection ensured that every new subsite would be configured correctly. However, that left me with over 80 site collections that needed to be manually updated to Eastern. In comes PowerShell.

 Clear-Host #Get a listing of all sites     $sites = (Get-SPSite -limit All).Url   #Get Eastern Time. Change to query your local time zone.       $timezone = [Microsoft.SharePoint.SPregionalSettings]::Globaltimezones | where-object { $_.Description -like "*eastern*" }       $timezoneID = $timezone.ID   #Warn about the pending changes       Write-Host -foregroundcolor yellow "Updating the timezone on all websites to $($timezone.Description)"       Write-Host "Press any key to continue or Ctrl-C to quit."       $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp")   #Update all sites with the new timezone       $num = 0   foreach ($site in $sites)   {       #If you don't have admin rights to a site, you will get the following error:       #The property 'ID' cannot be found on this object. Verify that the property exists and can be set.       $web = Get-SPWeb $site       If ($web.RegionalSettings.TimeZone.ID -ne $timezoneID)       {           $num += 1           Write-Host -foreground green "Updating timezone for $site"           $web.RegionalSettings.TimeZone.ID = $timezoneID           $web.Update()           $web.Dispose()       }   }   if ($num -eq 0)   {       Write-Host -foreground red "All sites have already been updated."   }   else   {       Write-Host -foreground red "Number of sites updated: $num"   }