ShareFlow
All articles

Tutorial

SharePoint regional settings: set them with PowerShell

Time zone, time format, work week: a PnP PowerShell script that sets the regional settings of many SharePoint sites at once, with a dry run, a log and a report.

Valentin Laurent13 min read
Share

SharePoint site regional settings decide how a site displays dates, times and numbers: the locale, the time zone, the 12- or 24-hour clock and the work week. A site set to the wrong time zone shows shifted times in "Modified" columns, lists and calendars. Fixing one site in the browser takes a minute; fixing thirty, each in its own country, is a chore. Here is a PnP PowerShell script that does it across many sites, runs a dry run before acting and keeps a record of every change.

What do a site's regional settings include?

In the web interface, they live in Site settings > Regional settings, under Site Administration. Only a site owner or site collection admin can change them. The script handles the ones that cause day-to-day trouble:

Setting in the interfaceScript parameterWhat SharePoint storesExample
Locale-LocaleIdA language code2057 = English (United Kingdom), 1033 = English (United States)
Time zone-TimeZoneIdA SharePoint-specific ID2 = London, 3 = Paris, 56 = Nairobi
Time format-Time24True or false$true for 14:30 instead of 2:30 PM
First day of week-FirstDayOfWeekA number, 0 = SundayMonday
Work days-WorkDaysA 7-bit maskMonday,Tuesday,...
Start and end time-WorkDayStart, -WorkDayEndMinutes since midnight08:00 = 480

The last three rows are why scripts get this wrong so easily: SharePoint stores neither "17:00" nor "Monday to Friday". It stores 1020 and 62. The script converts for you, and Get-PnPTimeZoneId -Match London gives you a time zone ID.

Site language, regional settings, personal settings: what is the difference?

Three things often get mixed up:

  • The site's default language is the language of the menus and of the libraries created with the site. Microsoft is clear: it cannot be changed after the site is created. You can only turn on alternate languages (Site settings > Language settings), which each user sees according to their own language. The script does not touch it.
  • The site's regional settings are the subject of this article. They apply to everyone who visits the site.
  • Each user's personal settings. By default a user follows the site; they can pick their own time zone and format, which then override the site's for them alone. A user who "still sees the wrong time" after your fix may have set their own.

For future sites, the default time zone is set once in the SharePoint admin center > Settings > Site creation. The script is for catching up on existing sites.

Prerequisites

They are the same as for the other scripts in this series, detailed in the article on bulk-restoring the recycle bin:

  1. PowerShell 7.4 or later (winget install --id Microsoft.PowerShell --source winget), started with pwsh;
  2. the PnP.PowerShell module (Install-Module PnP.PowerShell -Scope CurrentUser);
  3. your own Entra ID app for PnP PowerShell, required since September 2024: its application (client) ID is the script's ClientId;
  4. permissions: owner or admin of every site you change.

What the script does

  1. It builds the site list: URLs as a parameter, or a CSV file with different settings per site. An empty CSV cell falls back to the command-line value.
  2. It reads each site's current settings.
  3. It keeps only what changes. A setting that already matches is marked "Already compliant" and not rewritten.
  4. It applies the changes, except with -WhatIf: then it stops and records "Dry run: not changed".
  5. It reads the site again to check every value was saved.
  6. It logs everything: a .log file with all console output, and a .csv report with one row per setting (before, after, status). A failing site is recorded, and the script moves on to the next one.
Diagram of the script. Input: site URLs or a CSV file with one row per site. For each site: 1 read the current settings, 2 compare and keep only what changes, 3 apply unless in -WhatIf mode, 4 re-read to check every written value. Output: a .log file with all console output, errors included, and a .csv report with before, after and status per setting
How the script runs for each site, with its two record files

I tested it with PowerShell 7.7 and PnP.PowerShell 3.4.1 on the Demo site of my demo tenant: a dry run, a switch to the Nairobi time zone with a Sunday-to-Thursday week, a rollback to the original settings through a CSV, a locale change, and a site that does not exist, to check that the error gets recorded.

The full script

Copy it into a Set-SPRegionalSettings-en.ps1 file, or download it directly.

#Requires -Version 7.4
#Requires -Modules PnP.PowerShell

<#
.SYNOPSIS
    Applies regional settings (locale, time zone, time format, work week) to
    one or more SharePoint Online sites, with a log and a before/after report.

.DESCRIPTION
    For each site, the script:
      1. connects with PnP.PowerShell;
      2. reads the current regional settings;
      3. works out the requested changes (command-line parameters, overridden
         site by site by the CSV columns if you use a CSV);
      4. applies only what changes, then reads the site again to check;
      5. writes one row per setting to the CSV report: before, after, status.

    The whole run is also recorded in a log (Start-Transcript).
    With -WhatIf, nothing is changed: the report shows what would change.

.PARAMETER SiteUrl
    One or more site URLs. Use without -CsvPath.

.PARAMETER CsvPath
    CSV file (; separator) with a Url column and, if needed, LocaleId,
    TimeZoneId, Time24, FirstDayOfWeek, WorkDays, WorkDayStart, WorkDayEnd
    columns. An empty cell falls back to the command-line value.

.PARAMETER ClientId
    ID of the Entra ID app used by PnP.PowerShell (see the prerequisites).

.PARAMETER LocaleId
    Locale (date and number format), for example
    2057 = English (United Kingdom), 1033 = English (United States), 1036 = French (France).

.PARAMETER TimeZoneId
    SharePoint time zone ID, for example 2 = London, 3 = Paris.
    Get-PnPTimeZoneId -Match London returns the ID for a city.

.PARAMETER Time24
    $true for the 24-hour clock, $false for the 12-hour format (AM/PM).

.PARAMETER FirstDayOfWeek
    First day of the week: Monday, Sunday...

.PARAMETER WorkDays
    Work days: Monday, Tuesday, Wednesday, Thursday, Friday.

.PARAMETER WorkDayStart
    Start of the work day, HH:mm format (08:00).

.PARAMETER WorkDayEnd
    End of the work day, HH:mm format (17:00).

.PARAMETER ReportFolder
    Folder for the log and the report. Default: your Documents folder.

.EXAMPLE
    # 1) Dry run on two sites: nothing is changed
    .\Set-SPRegionalSettings-en.ps1 `
        -SiteUrl "https://contoso.sharepoint.com/sites/London", "https://contoso.sharepoint.com/sites/Manchester" `
        -ClientId "00000000-0000-0000-0000-000000000000" `
        -LocaleId 2057 -TimeZoneId 2 -Time24 $true -FirstDayOfWeek Monday -WhatIf

.EXAMPLE
    # 2) One setting per site, described in a CSV
    .\Set-SPRegionalSettings-en.ps1 -CsvPath .\sites.csv -ClientId "00000000-0000-0000-0000-000000000000"
#>

[CmdletBinding(SupportsShouldProcess)]
param(
    [Parameter(Mandatory, ParameterSetName = "Sites")] [string[]] $SiteUrl,
    [Parameter(Mandatory, ParameterSetName = "Csv")]   [string]   $CsvPath,
    [Parameter(Mandatory)] [string] $ClientId,
    [int]              $LocaleId,
    [int]              $TimeZoneId,
    [Nullable[bool]]   $Time24,
    [Nullable[System.DayOfWeek]] $FirstDayOfWeek,
    [System.DayOfWeek[]] $WorkDays,
    [string]           $WorkDayStart,
    [string]           $WorkDayEnd,
    [string]           $ReportFolder = (Join-Path $HOME "Documents")
)

$ErrorActionPreference = "Stop"

# ----------------------------------------------------------------------------
# Conversions to the SharePoint format
# ----------------------------------------------------------------------------

# Work hours are stored as minutes since midnight: 08:00 = 480.
function ConvertTo-Minutes([string] $Time) {
    $span = [TimeSpan]::ParseExact($Time, "hh\:mm", [Globalization.CultureInfo]::InvariantCulture)
    [int] $span.TotalMinutes
}

# Work days are a 7-bit mask read from Sunday (64) to Saturday (1):
# Monday to Friday = 0111110 = 62.
function ConvertTo-WorkDayMask([System.DayOfWeek[]] $Days) {
    $mask = 0
    foreach ($d in $Days) { $mask = $mask -bor (64 -shr [int]$d) }
    $mask
}

function ConvertFrom-WorkDayMask([int] $Mask) {
    $names = foreach ($d in 0..6) { if ($Mask -band (64 -shr $d)) { [System.DayOfWeek]$d } }
    ($names -join ",")
}

# ----------------------------------------------------------------------------
# Site list and the settings wanted for each one
# ----------------------------------------------------------------------------
$defaults = [ordered]@{
    LocaleId       = if ($PSBoundParameters.ContainsKey("LocaleId"))     { $LocaleId }     else { $null }
    TimeZoneId     = if ($PSBoundParameters.ContainsKey("TimeZoneId"))   { $TimeZoneId }   else { $null }
    Time24         = $Time24
    FirstDayOfWeek = $FirstDayOfWeek
    WorkDays       = if ($WorkDays) { ConvertTo-WorkDayMask $WorkDays } else { $null }
    WorkDayStart   = if ($WorkDayStart) { ConvertTo-Minutes $WorkDayStart } else { $null }
    WorkDayEnd     = if ($WorkDayEnd)   { ConvertTo-Minutes $WorkDayEnd }   else { $null }
}

if ($CsvPath) {
    $rows = Import-Csv -Path $CsvPath -Delimiter ";" -Encoding UTF8
} else {
    $rows = $SiteUrl | ForEach-Object { [PSCustomObject]@{ Url = $_ } }
}

$targets = foreach ($row in $rows) {
    $wanted = [ordered]@{}
    foreach ($key in $defaults.Keys) {
        $cell = if ($row.PSObject.Properties[$key]) { "$($row.$key)".Trim() } else { "" }
        $wanted[$key] = if ($cell -eq "") { $defaults[$key] } else {
            switch ($key) {
                "Time24"         { [bool]::Parse($cell) }
                "FirstDayOfWeek" { [System.DayOfWeek]$cell }
                "WorkDays"       { ConvertTo-WorkDayMask ([System.DayOfWeek[]]($cell -split "\s*,\s*")) }
                "WorkDayStart"   { ConvertTo-Minutes $cell }
                "WorkDayEnd"     { ConvertTo-Minutes $cell }
                default          { [int]$cell }
            }
        }
    }
    if ($null -ne $wanted.WorkDayStart -and $null -ne $wanted.WorkDayEnd -and $wanted.WorkDayEnd -le $wanted.WorkDayStart) {
        throw "Site $($row.Url): the work day must end after it starts."
    }
    [PSCustomObject]@{ Url = $row.Url.Trim(); Wanted = $wanted }
}

if (-not ($targets | ForEach-Object { $_.Wanted.Values } | Where-Object { $null -ne $_ })) {
    throw "No setting requested: give at least one, on the command line or in the CSV."
}

# ----------------------------------------------------------------------------
# Log and report
# ----------------------------------------------------------------------------
if (-not (Test-Path $ReportFolder)) { New-Item -ItemType Directory -Path $ReportFolder | Out-Null }
$stamp      = Get-Date -Format "yyyyMMdd-HHmmss"
$logPath    = Join-Path $ReportFolder "Regional-settings-$stamp.log"
$reportPath = Join-Path $ReportFolder "Regional-settings-$stamp.csv"
$report     = [System.Collections.Generic.List[object]]::new()

# The log keeps all console output, errors included, even with -WhatIf.
Start-Transcript -Path $logPath -WhatIf:$false | Out-Null

# Readable values for the report.
function Format-Value([string] $Name, $Value, $TimeZones) {
    if ($null -eq $Value) { return "" }
    switch ($Name) {
        "TimeZoneId"   { $tz = $TimeZones | Where-Object Id -eq $Value; "$Value $($tz.Description)" }
        "WorkDays"     { "$Value ($(ConvertFrom-WorkDayMask $Value))" }
        "WorkDayStart" { [TimeSpan]::FromMinutes($Value).ToString("hh\:mm") }
        "WorkDayEnd"   { [TimeSpan]::FromMinutes($Value).ToString("hh\:mm") }
        default        { "$Value" }
    }
}

function Get-CurrentSettings {
    $web = Get-PnPWeb -Includes RegionalSettings, RegionalSettings.TimeZone, RegionalSettings.TimeZones
    $rs  = $web.RegionalSettings
    [PSCustomObject]@{
        Rs        = $rs
        TimeZones = $rs.TimeZones
        Values    = [ordered]@{
            LocaleId       = [int]$rs.LocaleId
            TimeZoneId     = [int]$rs.TimeZone.Id
            Time24         = [bool]$rs.Time24
            FirstDayOfWeek = [System.DayOfWeek][int]$rs.FirstDayOfWeek
            WorkDays       = [int]$rs.WorkDays
            WorkDayStart   = [int]$rs.WorkDayStartHour
            WorkDayEnd     = [int]$rs.WorkDayEndHour
        }
    }
}

try {
    foreach ($t in $targets) {
        Write-Host "`nSite: $($t.Url)" -ForegroundColor Cyan
        try {
            # ----------------------------------------------------------------
            # 1. Connect and read
            # ----------------------------------------------------------------
            Connect-PnPOnline -Url $t.Url -Interactive -ClientId $ClientId
            $current = Get-CurrentSettings
            $rs      = $current.Rs

            # ----------------------------------------------------------------
            # 2. What changes
            # ----------------------------------------------------------------
            $changes = @($t.Wanted.Keys | Where-Object {
                $null -ne $t.Wanted[$_] -and $t.Wanted[$_] -ne $current.Values[$_]
            })

            if ($null -ne $t.Wanted.TimeZoneId -and -not ($current.TimeZones | Where-Object Id -eq $t.Wanted.TimeZoneId)) {
                throw "Unknown time zone $($t.Wanted.TimeZoneId). Look up the ID with Get-PnPTimeZoneId."
            }

            foreach ($name in $t.Wanted.Keys) {
                if ($null -eq $t.Wanted[$name]) { continue }
                $report.Add([PSCustomObject][ordered]@{
                    Date      = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
                    Site      = $t.Url
                    Setting   = $name
                    Before    = Format-Value $name $current.Values[$name] $current.TimeZones
                    After     = Format-Value $name $t.Wanted[$name] $current.TimeZones
                    Status    = if ($name -in $changes) { "To change" } else { "Already compliant" }
                })
            }

            if (-not $changes) { Write-Host "  Nothing to change."; continue }
            Write-Host ("  To change: {0}" -f ($changes -join ", "))

            # ----------------------------------------------------------------
            # 3. Apply (skipped with -WhatIf)
            # ----------------------------------------------------------------
            $siteRows = $report | Where-Object { $_.Site -eq $t.Url -and $_.Status -eq "To change" }
            if (-not $PSCmdlet.ShouldProcess($t.Url, "Change $($changes -join ', ')")) {
                $siteRows | ForEach-Object { $_.Status = "Dry run: not changed" }
                continue
            }

            # Unlike the web interface, changing LocaleId here does not reset the
            # other settings to their defaults: only the requested fields change.
            if ("LocaleId" -in $changes)       { $rs.LocaleId         = $t.Wanted.LocaleId }
            if ("TimeZoneId" -in $changes)     { $rs.TimeZone         = $current.TimeZones | Where-Object Id -eq $t.Wanted.TimeZoneId }
            if ("Time24" -in $changes)         { $rs.Time24           = $t.Wanted.Time24 }
            if ("FirstDayOfWeek" -in $changes) { $rs.FirstDayOfWeek   = [uint32]$t.Wanted.FirstDayOfWeek }
            if ("WorkDays" -in $changes)       { $rs.WorkDays         = [int16]$t.Wanted.WorkDays }
            if ("WorkDayStart" -in $changes)   { $rs.WorkDayStartHour = [int16]$t.Wanted.WorkDayStart }
            if ("WorkDayEnd" -in $changes)     { $rs.WorkDayEndHour   = [int16]$t.Wanted.WorkDayEnd }
            $rs.Update()
            Invoke-PnPQuery

            # ----------------------------------------------------------------
            # 4. Check: read the site again
            # ----------------------------------------------------------------
            $after = (Get-CurrentSettings).Values
            foreach ($row in $siteRows) {
                $ok = $after[$row.Setting] -eq $t.Wanted[$row.Setting]
                $row.Status = if ($ok) { "Changed" } else { "Mismatch after update: $(Format-Value $row.Setting $after[$row.Setting] $current.TimeZones)" }
            }
            Write-Host "  Done." -ForegroundColor Green
        }
        catch {
            # Missing permissions, site not found...: record it and move on.
            Write-Warning "  Failed: $($_.Exception.Message)"
            $report.Add([PSCustomObject][ordered]@{
                Date = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Site = $t.Url; Setting = "-"
                Before = ""; After = ""; Status = "Failed: $($_.Exception.Message)"
            })
        }
        finally {
            # Disconnect quietly if the connection failed.
            try { Disconnect-PnPOnline } catch { }
        }
    }
}
finally {
    # The report is written even if the script stops halfway.
    $report | Export-Csv -Path $reportPath -Encoding UTF8 -Delimiter ";" -WhatIf:$false
    $done = @($report | Where-Object Status -eq "Changed").Count
    Write-Host ("`n{0} setting(s) changed. Report: {1}" -f $done, $reportPath) -ForegroundColor Green
    Write-Host "Log: $logPath"
    Stop-Transcript -WhatIf:$false | Out-Null
}

Run it in two steps

First, the dry run. With -WhatIf, the script reads each site and writes the report, without changing anything:

.\Set-SPRegionalSettings-en.ps1 `
    -SiteUrl  "https://contoso.sharepoint.com/sites/Nairobi" `
    -ClientId "00000000-0000-0000-0000-000000000000" `
    -TimeZoneId 56 -Time24 $true `
    -WorkDays Sunday, Monday, Tuesday, Wednesday, Thursday `
    -WorkDayStart 07:30 -WorkDayEnd 16:30 -WhatIf

Here is the report from the test site, once the command ran again without -WhatIf:

SettingBeforeAfterStatus
TimeZoneId3 (UTC+01:00) Brussels, Copenhagen, Madrid, Paris56 (UTC+03:00) NairobiChanged
Time24TrueTrueAlready compliant
WorkDays62 (Monday,…,Friday)124 (Sunday,…,Thursday)Changed
WorkDayStart08:0007:30Changed
WorkDayEnd17:0016:30Changed

Then many sites at once with a CSV. One row per site, semicolon separator. Only the Url column is required; days are separated by commas:

Url;TimeZoneId;WorkDays;WorkDayStart;WorkDayEnd
https://contoso.sharepoint.com/sites/London;2;Monday,Tuesday,Wednesday,Thursday,Friday;09:00;17:30
https://contoso.sharepoint.com/sites/Nairobi;56;Sunday,Monday,Tuesday,Wednesday,Thursday;07:30;16:30
https://contoso.sharepoint.com/sites/Paris;3;;;
.\Set-SPRegionalSettings-en.ps1 -CsvPath .\sites.csv `
    -ClientId "00000000-0000-0000-0000-000000000000" -Time24 $true

Here -Time24 $true applies to every site, and the Paris site keeps its current hours because its cells are empty.

The log and the report are written to your Documents folder (or the -ReportFolder one), with the date and time in their names: Regional-settings-20261203-120640.log and .csv. Keep them: the report holds each site's "Before" values, so you can roll back by filling a CSV with them. That is how I put the test site back the way it was.

Pitfalls to know about

  • The interface and the script do not behave the same way. According to Microsoft, changing the locale in the web interface resets the other settings to the new locale's defaults. Through the script, it does not: on the test site, switching from 1036 to 1033 left the time zone, hours and time format untouched. If you change the locale, also pass the other settings you want.
  • Subsites are separate sites. The script sets the site whose URL you give. For an old subsite, add its URL to the list.
  • Personal settings win. A user who picked their own time zone will not see your change. That is not a script failure.
  • Time zone IDs are SharePoint-specific. They are not the Windows ones: use Get-PnPTimeZoneId. The script rejects an unknown ID and records it in the report.
  • Existing dates do not move. SharePoint stores them in universal time and displays them in the site's time zone: changing the time zone fixes the display without touching the data.

What I recommend

  1. Set the default time zone for new sites in the SharePoint admin center first, so you do not have to catch up on the next ones.
  2. Take stock: run the script with -WhatIf on all your sites with the expected settings. The report lists the ones that do not match.
  3. Prepare one CSV per country or region when your sites follow a per-country or per-department architecture: one site, one time zone, one work week.
  4. Apply, then keep the report and the log with the date of the change.
  5. Tell your support team: users who still see the old time probably have personal settings.

Automating with PnP PowerShell is part of the admin training I run, Run SharePoint at tenant scale. And if you want to straighten out a multi-country intranet, that is the kind of project I support through consulting.

Sources

Share this article

Know a colleague or client who deals with this? Send them the article in one click.

Read next

Comments

Loading comments…

Leave a comment

Comments are reviewed before they are published. Only your first name and last-name initial are shown.