0

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.

1

According to the PowerShell script that you provided, there was no error in my test.

enter image description here

The SharePointPnPPowerShellOnline module is being retired and all of that effort is being channeled to the PnP.PowerShell module. The SharePointPnPPowerShellOnline module will continue to be around for the on-prem versions of SharePoint Server (though not updated), but for SharePoint Online/Office 365/Microsoft 365 you’ll need to use the PnP.PowerShell module

Therefore, it is recommended that you install the latest PnP.PowerShell module in the SharePoint Online.

enter image description here

========================== Updated Answer =========================

enter image description here

enter image description here

2
  • Thanks for testing it. What happens if you run it more than once and create 3-5 sites in a row? I will definitely take a look at the new PnP.PowerShell to see if that could resolve the problem. Thanks. – Anders Apr 14 at 7:48
  • Hi, Anders N. It will still run normally, you can check my newly uploaded screenshots under original my answer. Have a nice day! – EchoDu_MSFT Apr 15 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.