Add a site language using powershell Pnponline or SPOService

Andy McRae 1 Reputation point
2022-08-18T14:03:33.583+00:00

Hi,
I create users via a ps command like this

New-MsolUser -UserPrincipalName $user.Email -Password $user.Password [...] -PreferredLanguage fr-FR

Knowing that the tenant is in German (de-DE) all the web apps are in german (See image)

232456-de.png

So i need to connect to the sharepoint site to be able to add french like this

232444-de-fr.png

But I need to do it with powershell because I make a lot of accounts daily with the script.

So I followed a "how to do" where it is given the ps commands like this:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell -SkipPublisherCheck -Force
$user = "Testuser@my_tenant.onmicrosoft.com"
$password = ConvertTo-SecureString 'a_secret_password_here' -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($user,$password)
Connect-PnPOnline -Url "https://tenant-my.sharepoint.com/personal/Testuser_tenant_onmicrosoft_com/_layouts/15/muisetng.aspx" -Credentials $creds
$Web = Get-PnPWeb
$Web.AddSupportedUILanguage(1036) (French)
$web.Update()
Invoke-PnPQuery

but the problem is that this only works if the user has logged in once manually on the sharepoint site, where all of a sudden it kind of creates the user sharepoint url "
"https://my_tenant-my.sharepoint.com/personal/Testuser_my_tenant_onmicrosoft_com/_layouts/15/muisetng.aspx"
It thicks the FR button like here
232434-frok.png
Otherwise i get the 404 not found error like this
232483-errors-404.png 2: /api/attachments/232444-de-fr.png?platform=QnA

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,600 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 30,991 Reputation points Microsoft Vendor
    2022-08-19T05:46:05.71+00:00

    Hi @Andy McRae
    Connect-PnPOnline site url should be like following

    https://tenant.sharepoint.com/site/xxx  
    

    In your case, The site url should be

    https://my_tenant-my.sharepoint.com/personal/Testuser_my_tenant_onmicrosoft_com  
    

    or

    https://my_tenant-my.sharepoint.com/personal  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.