1

I ran the following Powershell in Runbook and got an error. If there are any inappropriate parts in the logic, I would appreciate it if you could point them out.

Supplemental  When I changed the name to Get-PnPFolderItem instead of Get-PnPProvisioningTemplate and executed it, it worked fine.  Therefore, I think that Connect-PnPOnline is able to connect normally.

$TempSiteUrl = Get-AutomationVariable -Name 'SiteTemplateUrl'
$myCred = Get-AutomationPSCredential -Name SharePointConnect
Connect-PnPOnline -Url $TempSiteUrl -Credentials $myCred
Get-PnPProvisioningTemplate -Out template.xml

Error message

Get-PnPProvisioningTemplate : There is currently no connection yet. Use Connect-PnPOnline to connect.
At line:4 char:1
+ Get-PnPProvisioningTemplate -Out template.xml
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-PnPProvisioningTemplate], InvalidOperationException
    + FullyQualifiedErrorId : 
System.InvalidOperationException,PnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate
YuK
  • 13
  • 3

1 Answers1

0

Please try to use Get-PnPSiteTemplate instead: https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnpsitetemplate?view=sharepoint-ps

Michael Han
  • 3,475
  • 1
  • 6
  • 8
  • Thank you for your answer. I ran it using Get-PnPSiteTemplate instead of Get-PnPProvisioningTemplate, and I was able to connect to the SharePoint site successfully and get the template. Thank you so much!!! By the way, is there any difference between Get-PnPProvisioningTemplate and Get-PnPSiteTemplate? I am surprised that it stopped working because Get-PnPProvisioningTemplate was working normally until March of this year. – YuK Apr 12 '21 at 02:43
  • It used to be Get-PnPProvisioningTemplate. In the new version of PNP powershell, Get-PnPProvisioningTemplate has been replaced by Get-PnPSiteTemplate. – Michael Han Apr 12 '21 at 03:05
  • Thank you so much for letting me know! It helped me a lot! – YuK Apr 12 '21 at 04:10
  • You are welcome:) What's more, Apply-PnPProvisioningTemplate has been replaced by Invoke-PnPSiteTemplate. I think this would also be helpful to you. – Michael Han Apr 12 '21 at 05:45
  • Thank you!! That's exactly what I was doing, using Apply-PnPProvisioningTemplate to apply the template! When I changed it to Invoke-PnPSiteTemplate and ran it, I was able to apply the template successfully. By the way, "Recently used items" is displayed in the site navigation of the site after applying the template. Do you know how to prevent this from appearing when the template is applied? – YuK Apr 12 '21 at 08:37
  • When you using Get-PnPSiteTemplate to get the template, by default it would include the navigation of your site in the template. You could exclude the navigation with the parameter -ExcludeHandlers. Like this: Get-PnPSiteTemplate -ExcludeHandlers Navigation – Michael Han Apr 12 '21 at 08:48
  • Thank you for your answer. I would like to include in the template the items in the site navigation that I added myself. I would like to include my own site navigation items in the template, and also hide the "Recently used items" item from the site navigation. – YuK Apr 13 '21 at 08:03