pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
988 stars 665 forks source link

Language not set when creating a site in an App-Only authentication scenario using the New-PnPSite command with the specified LCID parameter #2618

Open haroldvandekamp opened 4 years ago

haroldvandekamp commented 4 years ago

Our tenant is using Security Defaults, so connecting using a username and password is not accepted anymore. Therefore, we want to use App-Only permissions to connect to the SharePoint environment, create modern team sites with a default language set to Dutch and do some additional modifications using the PnP Framework.

Using PnP version 3.20.2004.0 (April 2020 release) I am able to create a certificate, connect to the tenant and create an App Registration. We can create a modern team site without an exception being thrown. However, although we specified Dutch as our required base language, the created site has English as the base language.

We need the base language to be Dutch because the template that we regularly deploy to it and other solution that is depended on the provisioned sites.

image

Reporting an Issue or Missing Feature

Reporting an issue that the default language provided as the LCID parameter is ignored during site creation with the New-PnPSite command.

Expected behavior

When connected to SharePoint in an App-only context and subsequently creating a site using the New-PnPSite command with the LCID parameter set to 1043, we expect the created site to have a default language set to Dutch.

Actual behavior

Although we set the LCID parameter to the Dutch-language code 1043, the base language is not set to Dutch. Actually, the created site has English as the base language, which can be retrieved at the page located at https://TenantName.sharepoint.com/sites/SiteName/_layouts/15/muisetng.aspx.

Steps to reproduce behavior

Because our tenant is set to security defaults, we connected to the SharePoint tenant in an app-only context with the following command: Connect-PnPOnline -ClientId $AzureAppId -Tenant $tenantname -Url $adminUrl -CertificatePath $certificatePath

Subsequently, we created the site using the New-PnPSite command and the LCID parameter set to 1043 (Dutch): New-PnPSite -Type TeamSite -Title "DemoSite" -Alias "DemoSite" -Description "DemoSite" -Lcid 1043 -Owners "MeganB@TenantName.OnMicrosoft.com", "AlexW@TenantName.OnMicrosoft.com"

After the site has been created, navigate to the Site Information > View all site settings > Site languages page at https://TenantName.sharepoint.com/sites/SiteName/_layouts/15/muisetng.aspx. On this page, the base language is unexpectedly set to English instead of Dutch.

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

3.20.2004.0 (April 2020 release)

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

haroldvandekamp commented 4 years ago

Does this have something to do with the Microsoft Graph API suggestion "Set the language for Office 365 group" provided at https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/36775339-set-language-for-office365-group? That UserVoice idea mentions the following:

The Microsoft Graph API for creating and updating Office365 groups does not offer the option to set the language for the group

Is the New-PnPSite command using the Microsoft Graph API when connected to SharePoint in an App-Only situation? If so, is it true that the Microsoft Graph API for creating a group does not offer the option to set the language for the group and therefore the reason for this issue?

kachihro commented 4 years ago

Have just tested this using a PnP command - as per doco - this works correctly ;

New-PnPSite -Type CommunicationSite -Title ContosoX -Url https://TENANT.sharepoint.com/sites/contosoX -Lcid 1040

Refer to the examples ; https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/new-pnpsite?view=sharepoint-ps#examples

When viewing the SITE LANGUAGES page - it shows as Italian - which is correct (for 1040) ; /sites/contosoX/_layouts/15/muisetng.aspx

And then - tried using your command as above ;

New-PnPSite -Type TeamSite -Title "DemoSite" -Alias "DemoSite" -Description "DemoSite" -Lcid 1043 -Owners "myname@mytenant.com"

And - this worked also - showing as DUTCH.

This is using the following version of PnP PowerShell : https://www.powershellgallery.com/packages/SharePointPnPPowerShellOnline/**3.17.2001.2**

??? Perhaps there is a new bug/error - I'll try it again with the new/latest PowerShell... I've updated PowerShell - and the same WORKS as above. Perhaps @haroldvandekamp is correct - with regard to the AppOnly permissions...?

kachihro commented 4 years ago

Here's the code within the Site Create ; https://github.com/pnp/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Sites/SiteCollection.cs

Refer to code/comments with "graphAccessToken"

haroldvandekamp commented 4 years ago

Thanks for your reaction and research @kachihro. That is correct, I just did another test to compare the different scenario's.

Scenario 1: Create a Modern Team Site in an App-only authentication scenario. Specify the Dutch language ID (LCID 1043), however the site gets created with an English base language:

Connect-PnPOnline -ClientId $AzureAppId -Tenant $tenantname -Url $adminUrl -CertificatePath $certificatePath
New-PnPSite -Type TeamSite -Title "DemoSite" -Alias "DemoSite" -Description "DemoSite" -Lcid 1043 -Owners "MeganB@TenantName.OnMicrosoft.com", "AlexW@TenantName.OnMicrosoft.com"

Scenario 2: Create a Modern Team Site in a classic authentication scenario, e.g. using username and password. Specify the Dutch language ID (LCID 1043), indeed the site gets created with a Dutch base language:

Connect-PnPOnline -Url https://TenantName-admin.sharepoint.com
New-PnPSite -Type TeamSite -Title $sitename -Alias $sitename -Description $sitename -Lcid 1043

Scenario 1 (using App Only) is the one I need to use but isn't working as expected. Thank you @kachihro for pointing me to the PnP.Core library and the file https://github.com/pnp/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Sites/SiteCollection.cs. My App Only scenario seems to be calling the CreateTeamSiteViaGraphAsync method, which subsequently calls the OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.CreateUnifiedGroup method.

OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.CreateUnifiedGroup has no language parameter implemented The CreateUnifiedGroup method is shown at https://github.com/pnp/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Framework/Graph/UnifiedGroupsUtility.cs. I see zero text regarding "language" or "LCID", so it seems it has not been implemented in the PnP Core. Can other people confirm this?

Currently, the base language of newly created Modern Teams site might be based on the default language of the root site Other people familiar with the behavior described at https://github.com/SharePoint/sp-dev-docs/issues/1665:

It's the default language of the root site (at https://tenant.sharepoint.com) which is leading to the default language of the created modern (team/communication) sites. Removing this (classic) root site and recreating it in the preferred language is currently the only way to influence it

Next steps What is the best route for now?

heinrich-ulbricht commented 3 years ago

We don't even manage to create a site with app-only authentication. It always comes back with 401.

But reading the comments it seems that even if it did work we wouldn't get the right language set. 😣

moudhafersalhi commented 3 years ago

Thanks for your reaction and research @kachihro. That is correct, I just did another test to compare the different scenario's.

Scenario 1: Create a Modern Team Site in an App-only authentication scenario. Specify the Dutch language ID (LCID 1043), however the site gets created with an English base language:

Connect-PnPOnline -ClientId $AzureAppId -Tenant $tenantname -Url $adminUrl -CertificatePath $certificatePath
New-PnPSite -Type TeamSite -Title "DemoSite" -Alias "DemoSite" -Description "DemoSite" -Lcid 1043 -Owners "MeganB@TenantName.OnMicrosoft.com", "AlexW@TenantName.OnMicrosoft.com"

Scenario 2: Create a Modern Team Site in a classic authentication scenario, e.g. using username and password. Specify the Dutch language ID (LCID 1043), indeed the site gets created with a Dutch base language:

Connect-PnPOnline -Url https://TenantName-admin.sharepoint.com
New-PnPSite -Type TeamSite -Title $sitename -Alias $sitename -Description $sitename -Lcid 1043

Scenario 1 (using App Only) is the one I need to use but isn't working as expected. Thank you @kachihro for pointing me to the PnP.Core library and the file https://github.com/pnp/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Sites/SiteCollection.cs. My App Only scenario seems to be calling the CreateTeamSiteViaGraphAsync method, which subsequently calls the OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.CreateUnifiedGroup method.

OfficeDevPnP.Core.Framework.Graph.UnifiedGroupsUtility.CreateUnifiedGroup has no language parameter implemented The CreateUnifiedGroup method is shown at https://github.com/pnp/PnP-Sites-Core/blob/master/Core/OfficeDevPnP.Core/Framework/Graph/UnifiedGroupsUtility.cs. I see zero text regarding "language" or "LCID", so it seems it has not been implemented in the PnP Core. Can other people confirm this?

Currently, the base language of newly created Modern Teams site might be based on the default language of the root site Other people familiar with the behavior described at SharePoint/sp-dev-docs#1665:

It's the default language of the root site (at https://tenant.sharepoint.com) which is leading to the default language of the created modern (team/communication) sites. Removing this (classic) root site and recreating it in the preferred language is currently the only way to influence it

Next steps What is the best route for now?

I confirm this scenario. When creating the site(relatively the group) with a certificate authentification, the lcid parameter is ignored