Apply-PnPProvisioningTemplate : Cannot add part for the specified URI because it is already in the package.
I get this error when I try to apply a provisioning template that I have modified in PowerShell (see bottom of post).
I'm using Get-PnPProvisioningTemplate to make a copy of a Communication site, but as described in this thread (link), when I try to Apply the template, there's a buggy PnPField element that causes the process to fail. I can get the template to work by manually unzipping the PNP, removing the buggy PnPField element, then zipping it back up again, but I need it to happen automatically. Hence the script below.
However, after executing the below then applying the template, I get the error above.
It seems like the zipping process is making the PNP file incompatible with the cmdlet for some reason. I've compared file sizes, and when using the script to compress the folder back into the PNP file, it results in a file that's 1 KB smaller than if I compress it manually.