We have a simple PnP PowerShell script that seemingly works on the first execution, but not on consecutive executions.
We have this script running for other customers and have not heard of any problems with it before running it on a customer within the Azure US Government Cloud who also has ADFS configured.
Here's a snippet of the script:
Connect-PnPOnline -Url $adminSiteUrl -UseWebLogin $newSiteUrl = New-PnPSite -Type CommunicationSite -Title $siteTitle -Description $siteDescription -Url $siteCollectionUrl -Owner $siteOwner -SiteDesign Blank -Lcid 1033 -ErrorAction Stop -Wait Set-PnPTenantSite -Url $newSiteUrl -Owners $siteCollectionAdmins Connect-PnPOnline -Url $newSiteUrl -UseWebLogin $pnpSite = Get-PnPSite $app= Get-PnPApp -Identity $appId-ErrorAction Stop if(!$app.InstalledVersion){ $app| Install-PnPApp -ErrorAction Stop } else { Write-Host "App already installed." } The script also includes some additional steps like e.g.
- creating a local app catalog
- deploying modern packages to that app catalog
- updating site collection web properties
- applying a site design
Here are some of the errors they running into:
Set-PnPTenantSite : Cannot get site https:///xxx.sharepoint.com/sites/xxx
My initial thoughts on this was the we needed some way of waiting for the site to be fully created before trying to add site collection admins and I noticed we had the option of adding a -wait parameter to accomplish exactly that.
Docs can be found here: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/new-pnpsite?view=sharepoint-ps#parameters
That seemed to work better, but would still only work on 1 out of 3 tries.
Install-PnPApp : {"odata.error":{"code":"-2147024894, System.IO.FileNotFoundException","message":{"lang":"en-US","value":"File Not Found."}}}
This one is a bit special since as I mentioned they can run this script and install the app without any problem, but then all of the sudden on consecutive tries it will fail with the above mentioned error.
Install-PnPApp : {"odata.error":{"code":"-1, Microsoft.SharePoint.Client.UnknownError","mesage":{"lang:"en-US","value":"Unknown Error"}}}
Same as the above, but instead it's an unknown error.
I assume the customer is using SharePointPnPPowerShellOnline 3.25.2009.1, but I can't say for sure as I haven't been able to get this confirmed.
We've also asked them to try and upgrade to the latest version, but again haven't gotten any confirmation.
Any help is appreciated.



