Change OneDrive For Business locale

Hello, here I am back with another script to share with you. Recently a client asked me how to change locale of OneDrive in bulk for his Office 365 users. The thing is that his Office 365 tenant has been created with french as default language, whereas there are many englishspeaking people in the company.

All Excel files created in OneDrive online show formula in French. Really embarrassing for some users.

Excel issue0.png

Of course you can change this default language through OneDrive online site settings > Regional settings

Change OD4B locale3

But the big deal is how to manage it for more than twenty thousand users ? This is where you can leverage on the power of PowerShell. Here is a script to help you achieve this goal.

This script allows you to change regional settings in Office 365 OneDrive For Business.
    This script allows you to change regional settings in Office 365 OneDrive For Business.
Full path to upns TXT or CSV file (without header), one UserPrincipalName (upn) per line.
Specify Admintrator UserPrincipalName
Specify SharePoint Admin site url : "https://<yourtenant>", replace <tenant> with your tenant name
Specify OneDrive For Business url : "https://<yourtenant>, replace <tenant> with your tenant name
Specify the Locale ID. The locale ID for US english (en-us) is 1033
Set-OD4BLocale -UpnPath "C:\upns.txt" -creds "" -SiteURL "" -ODUrl "" -LocaleID 1033
Version : 1.0
Auteur : Jean-Marie AGBO
Date de création : 04/12/2018
Version 1.0 : Développement initial

Function Set-OD4BLocale{




[string]$LocaleID = "1033"

#Connect msol service
Connect-SPOService -Url $SiteURL -Credential $creds

#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
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"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

#Import upn file
$Upns = Get-Content -Path $UpnPath

foreach ($upn in $Upns){
#Building user ODrive Full Url
Write-Host "Building ODrive Full Url for $upn" -ForegroundColor Yellow
$ODriveFullUrl = $ODUrl + $Upn.Replace("@","_").replace('.','_')

#Adding Admin access to user OneDrive
Write-Host "Adding Admin access to $upn OneDrive" -ForegroundColor Yellow
Set-SPOUser -Site $ODriveFullUrl -LoginName $creds.UserName -IsSiteCollectionAdmin $true | Out-Null

#Bind to OD4B Site and change locale
Write-Host "Changing Locale for $upn" -ForegroundColor Yellow
$spocreds = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Creds.UserName,$creds.Password)
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($ODriveFullUrl)
$Context.Credentials = $spocreds
$Context.Web.RegionalSettings.LocaleId = $Locale

#Removing Admin access from User OneDrive
Write-Host "Removing Admin access from $upn OneDrive" -ForegroundColor Green
Set-SPOUser -Site $ODriveFullUrl -LoginName $creds.UserName -IsSiteCollectionAdmin $false | Out-Null

How to run the script ?

Set-OD4BLocale -UpnPath "C:\upns.txt" -creds "" -SiteURL "" -ODUrl "" -LocaleID 1033

The upns.txt file must contain the UserPrincipalName of users you want to change the locale.

You can get help on the script. Run it and use the below PowerShell command line :

Get-Help Set-OD4BLocale -Full

After changing the default language:

Change OD4B locale2

Now, you can check your change by creating an excel file in OneDrive Online and note that the formula are in english.


Et voilà 🙂 !