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.
Of course you can change this default language through OneDrive online site settings > Regional settings
<#
.SYNOPSIS
This script allows you to change regional settings in Office 365 OneDrive For Business.
.DESCRIPTION
This script allows you to change regional settings in Office 365 OneDrive For Business.
.PARAMETER UpnPath
Full path to upns TXT or CSV file (without header), one UserPrincipalName (upn) per line.
.PARAMETER creds
Specify Admintrator UserPrincipalName
.PARAMETER SiteURL
Specify SharePoint Admin site url : "https://<yourtenant>-admin.sharepoint.com/", replace <tenant> with your tenant name
.PARAMETER ODUrl
Specify OneDrive For Business url : "https://<yourtenant>-my.sharepoint.com/Personal/, replace <tenant> with your tenant name
.PARAMETER LocaleID
Specify the Locale ID. The locale ID for US english (en-us) is 1033
.EXAMPLE
Set-OD4BLocale -UpnPath "C:\upns.txt" -creds "admin@mytenant.onmicrosoft.com" -SiteURL "https://mytenant-admin.sharepoint.com/" -ODUrl "https://mytenant-my.sharepoint.com/Personal/" -LocaleID 1033
.NOTES
Version : 1.0
Auteur : Jean-Marie AGBO
Date de création : 04/12/2018
Version 1.0 : Développement initial
#>
Function Set-OD4BLocale{
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)]
[String]$UpnPath,
[parameter(Mandatory=$true)]
[PSCredential]$creds,
[parameter(Mandatory=$true)]
[string]$SiteURL,
[parameter(Mandatory=$true)]
[string]$ODUrl,
[parameter(Mandatory=$false)]
[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.ExecuteQuery()
$Context.Web.RegionalSettings.LocaleId = $Locale
$Context.Web.Update()
$Context.ExecuteQuery()
#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 "admin@mytenant.onmicrosoft.com" -SiteURL "https://mytenant-admin.sharepoint.com/" -ODUrl "https://mytenant-my.sharepoint.com/Personal/" -LocaleID 1033
The upns.txt file must contain the UserPrincipalName of users you want to change the locale.
fname1@mytenant.com
fname2@mytenant.com
fname3@mytenant.com
fname4@mytenant.com
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:

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

Et voilà 🙂 !
i have tried to run this script it ran but did not change the language of the onedrive site for the users .
:+
LikeLike
Hi Daniel,
The purpose of this script is not to change the onedrive site language but the regional settings. Regional settings allow you to specify how the site displays numbers, dates, and times.
If you want to change your OneDrive display language, you must do it in the settings of your Office 365 account : https://support.office.com/en-us/article/change-your-display-language-and-time-zone-in-office-365-for-business-6f238bff-5252-441e-b32b-655d5d85d15b
LikeLike
When i run this script i get the following error “Exception calling “.ctor” with “2” argument(s): “The ‘username’ argument cannot be null.” Do you have any idea what l’m doing wrong?
Thanks
LikeLike
I did not faced this error before. Did you try to run the script for one upn ? I could be available for a screen share during this week if you want.
LikeLike
when I try to run the script, simply nothing happens. not sure why. are there any prerequisites for the script to run on a windows 10 system?
LikeLike
Hi, PowerShell module for SharePoint Online is required for running the script.
LikeLike
Trying to work out what the locale ID would be – eg for English Australia or English UK – I assume the 1033 is for French?
LikeLike
Please visit the below website, in the column LCID Decimal, you could find the locale ID you are looking for :
https://www.science.co.il/language/Locale-codes.php
Thanks
LikeLike
Very good script, especially that you can specify the UPNs. I am having trouble running the script though. I have saved the script as Set-OD4BLocale.ps1, but when running it nothing happens. I have installed CSOM and Sharepoint Online Module.
.\Set-OD4BLocale.ps1 -UpnPath “C:\Scripts\upns.txt” -creds “user@tenant.com” -SiteURL “https://tenant-admin.sharepoint.com/” -ODUrl “https://tenant-my.sharepoint.com/Personal/” -LocaleID 2057
LikeLiked by 1 person
Just found my own error. Would help if I read the script properly and saw that it is a function. Working now!
LikeLiked by 1 person
Great !
LikeLike
Having the same issue as Wian Swart – when running the .\Set-OD4BLocale.ps1 – nothing happens – not sure how to use/call the function – can you show me specifics on how how to run this
LikeLike
Thanks! Working great, but I also need to change the “Specify the sort order” to General at the same time. Is there a way to add this into the script?
LikeLike
Ran the script and it does state:
Building ODrive Full Url for User@domain.com
Adding Admin access to User@domain.com
Changing Locale for User@domain.com
Removing Admin access from User@domain.com OneDrive
Logged in users onedrive but language has not been changed. Does it take long time to relfect changes? Been waiting few hours now.
LikeLike
Ran the script and it does state:
Building ODrive Full Url for User@domain.com
Adding Admin access to User@domain.com
Changing Locale for User@domain.com
Removing Admin access from User@domain.com OneDrive
Logged in users onedrive but language has not been changed. Does it take long time to relfect changes? Been waiting for almost a day now..
LikeLike
Hey. The script is giving access to the admin I specify and removes access at the end, but the locale doesn’t change and i don’t get any errors. I tried different decimal locale Ids . Thank you!
LikeLike