首页 > 解决方案 > PowerShell、SharePoint:获取 PnPSiteTemplate 错误

问题描述

我在使用 PnP PowerShell cmdlet 时遇到错误:Get-PnPSiteTemplate。我也是全局管理员和网站集管理员。

启用自定义脚本:

set-sposite https://tenant.sharepoint.com/sites/TestSite -denyaddandcustomizepages $false

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/TestSite -Interactive

Get-PnPSiteTemplate -Out "C:TempDemo.xml"

Get-PnPSiteTemplate : Attempted to perform an unauthorized operation.
At C:\Users\userX\Desktop\Script.ps1:3 char:1
+ Get-PnPSiteTemplate -Out "C:TempDemo.xml"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPSiteTemplate], ServerUnauthorizedAccessException
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.GetSiteTemplate

任何人的想法?MS说PnP是开源的,所以没有真正的支持......

目标是将包含所有项目和元数据的完整 SharePoint 列表复制到另一个站点。像这样: https ://www.drware.com/copy-a-list-with-list-items-to-another-site/

谢谢!:)

标签: powershellsharepoint

解决方案


我在一个干净的通信站点上使用最新版本的 PnP.PowerShell(版本 1.7.0)重新检查了该命令,其中包含一个包含几个项目的示例列表,仅此而已,并且可以正常工作。

  1. 您是否也可以先使用一个自定义列表在某个测试干净的站点上重试,看看是否有相同的错误?也许您遇到的问题与您在此站点上的某些自定义有关,因为Get-PnPSiteTemplate没有任何参数将导出整个站点的模板(包括列表,还有所有其他内容,例如一些您可能没有的自定义应用程序)允许这样做)

  2. 您可以尝试的另一件事是运行 cmdlet 以仅检索您感兴趣的列表以及数据:

# this will export the template only of the selected list
Get-PnPSiteTemplate -Out "C:\TempDemo.xml" -ListsToExtract "testList" -Handlers Lists -Force

# this will populate the list with data of the list
Add-PnPDataRowsToSiteTemplate -Path "C:\TempDemo.xml" -List "testList"

推荐阅读