pnp / PnP-PowerShell

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

[BUG] Saving PnP Powershell Teams Provisioning with in-memory template changes #2827

Open acksoft opened 4 years ago

acksoft commented 4 years ago

Expected behavior

Executing Save-PnPTenantTemplate should export all properties (as defined in the 2002 02 schema) that are in the script

Actual behavior

Some properties only show up when they have certain values, and others not at all

Steps to reproduce behavior

I am working on a script that uses PnP PowerShell to read in a Tenant Template, makes changes to the template in memory by adding a new team and setting its properties, then saving the result out to a new tenant template (currently .xml but could be .pnp in the future). We save the resulting template so that it can be referenced later, after it has been applied, to resolve any questions that might come up about why the resulting team is configured the way it is.

The reason I am posting this is that the Save-PnPTenantTemplate cmdlet is displaying some odd behavior. I start by getting the existing template into memory, then creating a new Team:

#--- Read in existing tenant template
$tenant = Read-PnPTenantTemplate -Path.\tenant-template.xml
#--- Create new team object and set some properties
$y = New-Object -TypeName OfficeDevPnP.Core.Framework.Provisioning.Model.Teams.Team
$y.DisplayName = "Team added Interactively"
$y.MailNickname = "TAI"
$y.Visibility = "Public"
$y.Description = "Show a team can be created in code"

I then add a new FunSettings object to the team object and set its properties like so:

#--- Add the fun settings object and its member values
$y.FunSettings = New-Object -TypeName OfficeDevPnP.Core.Framework.Provisioning.Model.Teams.TeamFunSettings
$y.FunSettings.AllowCustomMemes = $true
$y.FunSettings.AllowGiphy = $true
$y.FunSettings.AllowStickersAndMemes = $true
$y.FunSettings.GiphyContentRating = "Strict" #--- value limited to "Strict" or "Moderate"

Then I add the team to the template and save it back to a file:

#--- add the team to the tenant template
$tenant.Teams.Teams.Add($y)
#--- Now export the template to a new file to see our results
Save-PnPTenantTemplate -Template $tenant -Out .\tenant-template-added.xml

The result is surprising. The pnp:Team node has its properties as expected, but the pnp:FunSettings node is completely empty of the properties that I defined in the script:

    <pnp:Team DisplayName="Team added Interactively" Description="Show a team can be created in code" Visibility="Public" Specialization="None" MailNickname="TAI">
      <pnp:FunSettings />

What's even stranger is that when I change the FunSettings property values in the script to different values, they begin to show up in the template:

$y.FunSettings.AllowCustomMemes = $false
$y.FunSettings.AllowGiphy = $false
$y.FunSettings.AllowStickersAndMemes = $false
$y.FunSettings.GiphyContentRating = "Moderate" #--- value limited to "Strict" or "Moderate"

Gives the following result:

 <pnp:Team DisplayName="Team added Interactively" Description="Show a team can be created in code" Visibility="Public" Specialization="None" MailNickname="TAI">
      <pnp:FunSettings AllowGiphy="false" AllowStickersAndMemes="false" AllowCustomMemes="false" />

My question is why? Why do these properties only show up in the exported template with certain values? And why is the GiphyContentRating property not showing up at all (in either scenario)? I notice that the GiphyContentRating is in the 2020-02 schema, so I am curious why Save-PnPTenantTemplate will not export it.

Note that this behavior is not restricted to the FunSettings. Depending on the values set, many of the other settings (like MemberSettings and MessagingSettings for example) also sometimes get exported and sometimes don't.

For the business to trust my solution, I need to be able to show the flow of values from my configuration file [not used in this Proof Of Concept script] to the template and then to the new Team itself. If some of the properties don't show up sometimes, that is not going to inspire confidence with my customer.

Please advise me about what might be going on here. If this is a new or known issue, or if I am missing something fundamental, that will be good to know. Thank you for listening.

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

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

3.23.2007.1

How did you install the PnP-PowerShell Cmdlets?

acksoft commented 3 years ago

It has been a few weeks -- is there any feedback that anyone can provide on this issue?

Thanks.