0

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)

Apps German

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

FR-SP

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://my_tenant-my.sharepoint.com/personal/Testuser_my_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"

If it was done before (Just logging in and not thicking the FR button), the script thicks the button like here:

FR-Thicked

Otherwise i get the 404 not found error like this

Error 404

Any Ideas how to do it without having to log in?

1 Answers1

0

Ok so I got in touch with the Microsoft Support and they told me that the Onedrive site, which causes the Error 404, is not created until the user logs in to onedrive admin site. And so one must first pre provision the personal account like shown on the microsoft documentations website Onedrive, the code looks like this:

> $user = "userXX@tenant.onmicrosoft.com"
> $password = ConvertTo-SecureString 'my_personal_password' -AsPlainText -Force
> $creds = New-Object System.Management.Automation.PSCredential ($user,$password)
> Connect-MsolService -Credential $creds
> Connect-SPOService -Url "https://[userXX]-admin.sharepoint.com" -Credential $creds
> Request-SPOPersonalSite -UserEmails "[userXX]@[tenant].onmicrosoft.com"
> # The provisioning takes some time, so if one connects directly after creation, 
> #then the 404 error happens again, so we put a pause to the script
> Start-sleep -seconds 30
> Connect-PnPOnline -Url "https://tenant-my.sharepoint.com/personal/[userXX]_[tenant]_onmicrosoft_com/_layouts/15/muisetng.aspx" -Credentials $creds
> $Web = Get-PnPWeb
> $web.IsMultilingual = $true
> $Web.AddSupportedUILanguage(1036) #(French)
> $web.Update()
> Invoke-PnPQuery

So, the variables are [UserXX] and [tenant] which are basically the created user and the company's (or personal) name