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.

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:

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.

Excel-issue-e1546263940174.png

Et voilà 🙂 !

16 thoughts on “Change OneDrive For Business locale

Add yours

  1. i have tried to run this script it ran but did not change the language of the onedrive site for the users .
    :+

    Like

    1. 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

      Like

  2. 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

    Like

  3. 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?

    Like

  4. Trying to work out what the locale ID would be – eg for English Australia or English UK – I assume the 1033 is for French?

    Like

  5. 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

    Liked by 1 person

  6. 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

    Like

  7. 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?

    Like

  8. 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!

    Like

Leave a comment

Blog at WordPress.com.

Up ↑