How to change Timezone for all Sharepoint Sites or Teams

Mehdi ZENBIL 1 Reputation point
2021-03-11T12:56:55.537+00:00

Hello everybody,

I have near 600 SharePoint Online sites which are in a bad timezone.
I just ask to the community if it is possible to change with a powershell script the Regional Settings automatically.

Can you help me please?

Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ChelseaWu-MSFT 6,321 Reputation points
    2021-03-12T01:41:26.223+00:00

    Here is a sample script to change tenant wide time zone settings for your reference:

    #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
        }
    }
    
    
    #Parameters
    $AdminSiteURL = "https://<tenant>-admin.sharepoint.com/"
    $TimezoneName = "(UTC) Coordinated Universal Time"
    
    #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
    }
    

    Please remember to change the parameters corresponding to your tenant’s name and required time zone, and also the path of the SharePoint CSOM Assemblies if necessary.

    Here is another sample script to get the available time zones in SharePoint Online:

    #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://<tenant>.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
    

    Reference: SharePoint Online: Change Time Zone using PowerShell.

    *Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link. *


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    **Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. **