SharePoint Online: Change Time Zone using PowerShell

Requirement: Change the 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. In this article, we will show you how to change the timezone for SharePoint Online.

SharePoint Online timezone settings can be set by going to :

  1. Site Settings >> Click on “Regional Settings” under “Site Administration”.
  2. On the Regional settings page, You can set the time zone, locale, and other regional settings.
    sharepoint online change timezone powershell
  3. Click the “OK” button at the bottom right of the page to save your changes.

The new time zone setting should reflect immediately in all timestamps displayed on lists and libraries, and also the date field values used.

Please note, You must have Site Collection Administrator rights on all SharePoint Online Site collections to change the Timezone Regional settings. And you need a 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 a description to update the SharePoint Online site’s timezone. 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

#sharepoint online powershell to get time zone
$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 to 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 obtain the time zone ID or description, You can change the time zone using the 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 the 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 -URL $SiteURL -Interactive

#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 the default timezone of the SharePoint Online site.

Set Time Zone for SharePoint Online Site Collection using PowerShell:

As the time zone settings are managed at the site (web) scope, setting the time zone on 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

Set Default Timezone in SharePoint Online – Tenant wide

To set the default timezone for new sites you’ll create in the future in SharePoint Online, do the following:

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

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

How about changing the 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 the 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 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 - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

  • Has anyone managed to get this working with MFA?

    I want to change the time zone for existing SharePoint Online site collections and I can’t get the script that is used in here to work with MFA.

    Please help.

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

    Reply
    • 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
  • 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
  • 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
  • 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
    • I have updated the article with a script to iterate through all sites in the tenant. Please check.

      Reply
  • 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
    • 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
  • 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
    • 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
  • 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
  • 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
    • 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
    • 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
  • 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
    • 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

Your email address will not be published. Required fields are marked *