SharePoint Online: Change Time Zone using PowerShell

Requirement: Change Timezone in SharePoint Online.

How to Change Timezone in SharePoint Online?

As a global organization operating in different regions and time zones, we wanted to set time zones for respective sites since users get annoyed when they see Pacific time zones in the uploaded document’s time stamps. SharePoint Online timezone settings can be set by going to :

  • Site Settings >> Click on “Regional Settings” under “Site Administration”
  • On the Regional settings page, You can set the time zone, locale, and other regional settings.
    sharepoint online change timezone powershell
  • Click on OK located at the bottom right of the page to save your changes.
Please note, You must have Site Collection Administrator rights on all SharePoint Online Site collections in order to change the Timezone Regional settings. And you need SharePoint Online Administrator or Tenant Admin to apply it on tenant wide.

Get a List of All Available Time Zones in SharePoint Online: 

We need either the ID of the time zone or description in order to update the timezone of a SharePoint Online site. To get a list of time zones, you can either pick it from the Time zones drop-down of the above page or use this PowerShell to get all available time zones list.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#SharePoint Online Site URL
$SiteURL = "https://crescent.sharepoint.com/"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#Get all available time zones
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()

#Get Timezone ID and Description
$Timezones | Select ID, Description

This retrieves all available time zones ID and description fields.

sharepoint online get timezone

You can also refer this Microsoft article for available timezone values: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ms453853(v=office.15)?redirectedfrom=MSDN

SharePoint Online: Change Timezone using PowerShell

Once you obtained the time zone ID or description, You can change the time zone of a site using PowerShell script.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config parameters for SharePoint Online Site URL and Timezone description
$SiteURL = "https://crescent.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#Get all available time zones
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()

#Filter the Time zone to update
$NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}

#sharepoint online powershell set time zone
$Ctx.Web.RegionalSettings.TimeZone = $NewTimezone
$Ctx.Web.Update()
$Ctx.ExecuteQuery() 

PnP PowerShell to Change Timezone in SharePoint Online:

Here is how to set time zone in SharePoint Online with Pnp PowerShell.

#Set Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$TimezoneName = "(UTC+04:00) Abu Dhabi, Muscat"

#Connect to SharePoint Online with PnP PowerShell
Connect-PnPOnline $SiteURL -UseWebLogin

#Get the Web
$web = Get-PnPWeb -Includes RegionalSettings.TimeZones

#Get the time zone
$Timezone  = $Web.RegionalSettings.TimeZones | Where {$_.Description -eq $TimezoneName}

If($Timezone -ne $Null)
{
    #Update time zone of the site
    $Web.RegionalSettings.TimeZone = $Timezone
    $Web.Update()
    Invoke-PnPQuery
    Write-host "Timezone Updated Successfully!" -ForegroundColor Green
}
else
{
    Write-host "Timezone $TimezoneName not found!" -ForegroundColor Yellow
}

Similarly, you can update Locale, Time format and other regional settings:

$Ctx.web.RegionalSettings.time24 = $True
$Ctx.web.RegionalSettings.LocaleId = 1043

This PowerShell sets default timezone  of the SharePoint Online site.

Set Time Zone for SharePoint Online Site Collection using PowerShell:

As time zone settings are managed at site (web) scope, setting time zone on each and every site is cumbersome. Time zone settings at the top-level site collection don’t affect/propagate automatically to sub-sites. So let’s change the timezone for the SharePoint Online site collection using PowerShell.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to change Timezone regional settings of a SharePoint Online site
Function Set-SPOTimeZone
{ 
    Param ([Microsoft.SharePoint.Client.Web]$Web,[Microsoft.SharePoint.Client.TimeZone]$Timezone)

    Try
    {
        #Update the timezone of the site
        $Web.RegionalSettings.TimeZone = $NewTimezone
        $Web.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "Timezone has been updated for "$Web.Url

        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery()

        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Timezone for the web
            Set-SPOTimeZone -Web $Subweb -Timezone $NewTimezone
        }
    }
    Catch [System.Exception]
    {
        Write-Hoste -f Red $_.Exception.Message
    }  
}

#Config parameters for SharePoint Online Site Collection URL and Timezone description
$SiteURL = "https://crescent.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials
  
#Get the Root web from given Site Collection URL
$Web = $Ctx.web
$Ctx.Load($Web)

#Get the Time zone to update
$Timezones = $Ctx.Web.RegionalSettings.TimeZones
$Ctx.Load($Timezones)
$Ctx.ExecuteQuery()
$NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}
 
#Call the function to set Timezone for the Root web
Set-SPOTimeZone -Web $web -Timezone $NewTimezone

Change Timezone in SharePoint Online – Tenant wide

To set the default timezone in SharePoint Online, do the following:

  • Login to SharePoint Admin Center >> Click on “Settings” in the left navigation >> Click on “Site Creation”.
  • On the Site Creation page, select the default timezone for new site collections.
    set default timezone for sharepoint online

This sets the default time zone for new site collections you create.

How about changing time zone for existing SharePoint Online site collections?

We can set the time zone for all existing site collections in SharePoint Online – tenant wide using the below PowerShell script. This script simply loops through all sites and changes the default timezone. Just set $AdminSiteURL and $TimezoneName variables in the script and provide the credentials to connect to SharePoint Online Admin center once.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#function to change Timezone regional settings of a SharePoint Online site
Function Set-SPOnlineTimeZone([String]$SiteURL,[String]$TimezoneName,[PSCredential]$Cred)
{ 
     Try
     {
        #Setup Credentials to connect
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
        #Set up the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $credentials
  
        #Get the Root web from given URL
        $Web = $Ctx.web
        $Ctx.Load($Web)

        #Get the Time zone to update
        $Timezones = $Web.RegionalSettings.TimeZones
        $Ctx.Load($Timezones)
        $Ctx.ExecuteQuery()
        $NewTimezone = $Timezones | Where {$_.Description -eq $TimezoneName}
 
        #Update the timezone of the site
        $Web.RegionalSettings.TimeZone = $NewTimezone
        $Web.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "Timezone has been updated for "$Web.Url

        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery()

        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Timezone for the web
            Set-SPOnlineTimeZone -SiteURL $Subweb.URL -TimezoneName $TimezoneName -Cred $AdminCredentials
        }
   }
    Catch [System.Exception]
    {
        Write-Host -f Red $_.Exception.Message
    } 
} 

#Config parameters for SharePoint Online Admin Center and Timezone description
$AdminSiteURL = "https://crescent-admin.sharepoint.com/"
$TimezoneName ="(UTC+04:00) Abu Dhabi, Muscat"

#Get credentials to connect to SharePoint Online Admin Center
$AdminCredentials = Get-Credential

#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $AdminCredentials

#Get all Site Collections
$SitesCollection = Get-SPOSite -Limit ALL

#Iterate through each site collection
ForEach($Site in $SitesCollection)
{
    Write-host -f Yellow "Setting Timezone for Site Collection:"$Site.URL

    #Call the function to set Timezone for the site
    Set-SPOnlineTimeZone -SiteURL $Site.URL -TimezoneName $TimezoneName -cred $AdminCredentials
}

Here is my another post on setting time zone and other regional settings in SharePoint On-premises Change Regional Settings, Time zone, Locale in SharePoint 2013 using PowerShell

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

20 thoughts on “SharePoint Online: Change Time Zone using PowerShell

  • July 2, 2021 at 7:52 AM

    Hi All, Is there a way to set up Daylight Saving Time on SahrePoint 365?

    Reply
    • September 9, 2021 at 1:44 PM

      SharePoint stores date/time as per UTC time. It will adjust daylight-saving depending on the time zone you have set as the default time zone.

      Reply
  • May 17, 2021 at 2:45 PM

    I get the same for the majority of the list, the sites that are accessible are the sites that I already have an admin role assigned to.

    It’s odd as I am a global administrator, i’ve assigned myself the sharepoint administrator role also, but i’m sure the global administrator has the same rights to the sharepoint sites.

    Do you know of any other roles needed or do we really have to be an admin of each site?

    Reply
  • March 11, 2021 at 8:25 AM

    Hello,
    I try to folllow this tutorial but I have an error when I execute the script :
    the remote server return an error : (403) Forbidden.
    Do you know why ?

    Reply
  • November 19, 2020 at 12:14 AM

    Hi Saludeen,

    Thank you for these great pages. I’ve managed to fix our timezone issue with your help. I’m now trying to set all of the regional settings for all sites with one script, i’ve tried merging your two scripts to avoid updating each site individually to no avail.

    Do you have a script that will allow me to change all of the regionalsettings.$ for all sites in one hit?

    Reply
    • September 9, 2021 at 1:50 PM

      I have updated the article with a script to iterate through all sites in the tenant. Please check.

      Reply
  • August 6, 2020 at 4:48 PM

    hi there, this is a great page, thanks!
    Trying to change timezones of all existing sites, and get this error:

    Set-SPOnlineTimeZone : The term ‘Set-SPOnlineTimeZone’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
    a path was included, verify that the path is correct and try again.
    At line:6 char:5

    Any ideas?

    Reply
    • August 6, 2020 at 6:14 PM

      Hi There,
      Set-SPOnlineTimeZone is a custom function defined in my script. Make sure you are copying and using the script along with that function.

      Reply
  • May 12, 2020 at 3:03 PM

    Just an update from me to say I worked around the MFA issue using an App Password. I then also needed to add myself as an ‘Additional Site Admin’ which I did as part of the script.

    Reply
    • May 12, 2020 at 4:24 PM

      Yes! App password works. Also, You can skip “Credential” parameter from Connect-SPOService cmdlet, So that you’ll get a popup to enter your credentials which is MFA aware.
      E.g. Connect-SPOService -URL $AdminSiteURL

      Reply
  • May 12, 2020 at 12:29 PM

    I’m just getting: The remote server returned an error: (403) Forbidden. on every site I’m not a member of. I have MFA enabled and can’t work out what’s required to change the Tenant wide script to work with MFA.

    Reply
  • December 25, 2019 at 5:16 AM

    I’m getting: Exception calling “ExecuteQuery” with “0” argument(s): “The sign-in name or password does not match one in the Microsoft account system.” error!

    Reply
    • December 25, 2019 at 5:19 AM

      When you use two-factor authentication, Leave the -credential parameter to Connect-SPOService cmdlet. You’ll get a prompt (which is 2FA aware) to enter your user name and password. Or use PnP PowerShell to handle two-factor authentication.

      Reply
    • December 8, 2020 at 11:21 PM

      Hi Salaudeen,
      I’m trying to (firstly) get a list of Timezones by using your script at “Get a List of All Available Time Zones in SharePoint Online”. However, I’m getting the same error as Anonymous above. However, I don’t see the Connect-SPOService cmdlet in your script for getting a list of all available time zones.
      I’m using Windows PowerShell ISE run as an Administrator. I have: Microsoft.Online.SharePoint.PowerShell 16.0.20717.12000 installed.

      Reply
  • August 30, 2019 at 2:34 AM

    Do you aware any impact for the timezone settings? The timezone setting seems not related to any SharePoint features. The OOTB usage reports are using GMT and have no way to change….

    Reply
    • August 6, 2020 at 6:16 PM

      SharePoint internally stores date and time values in UTC format. Any timezone applied just presents the data in respective timezone’s respective value.

      Reply

Leave a Reply