Graph and PowerShell Blog | About | Links
Set OneDrive for Business Locale
08-Mar-23

By default all Sharepoint sites in Office365 will default to the en-US locale. This means things like dates and timestamps will be displayed in mm/dd/yyyy format and can cause confusion for users. While Sharepoint sites for Teams can be set with a new default template it seems that this is not possible for user's of OneDrive for Business, with the template instead being read-only.

So it seems you can only do this in one large batch every few months to be workable. To enable this we use PnP PowerShell and assign it the correct Azure AD app permissions needed. The code was as follows:

Connect-PnPOnline https://tenant.sharepoint.com/sites/yoursite
$LocaleId = 6153 # en-ie
$TimeZoneId = 2 # Dublin

$web = Get-PnPWeb -Includes RegionalSettings,RegionalSettings.TimeZones
$timeZone = $web.RegionalSettings.TimeZones | Where-Object {$_.Id -eq $TimeZoneId}
$web.RegionalSettings.LocaleId = $LocaleId
$web.RegionalSettings.TimeZone = $timeZone
$web.Update()
Invoke-PnPQuery

But when we ran this we got an access denied error. The workaround was to temporarily give the admin access to each OneDrive site and then remove the access after:

Connect-PnPOnline -url https://tenant.sharepoint.com/ -interactive

$adminAcctToAdd = "MrAdmin@domain.com" #Admin account we want to add
#Get OneDrive sites
$sites=Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/'"
foreach($site in $sites)
{
 $s_url = $site.url

 if ($s_url -like "*")
 {
  #Add Admin account as an additional site collection adminstrator
  Set-PnPTenantSite $site.url -Owners $adminAcctToAdd

  Connect-PnPOnline $site.Url -interactive
  $web = Get-PnPWeb -Includes RegionalSettings,RegionalSettings.TimeZones
  $timeZone = $web.RegionalSettings.TimeZones | Where-Object {$_.Id -eq $TimeZoneId}
  $web.RegionalSettings.LocaleId = $LocaleId
  $web.RegionalSettings.TimeZone = $timeZone
  $web.Update()
  Invoke-PnPQuery

  #Later we can remove the added admin
  Remove-PnPSiteCollectionAdmin -Owners $adminAcctToAdd
 }
}