powershell - 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/
谢谢!:)
解决方案
我在一个干净的通信站点上使用最新版本的 PnP.PowerShell(版本 1.7.0)重新检查了该命令,其中包含一个包含几个项目的示例列表,仅此而已,并且可以正常工作。
您是否也可以先使用一个自定义列表在某个测试干净的站点上重试,看看是否有相同的错误?也许您遇到的问题与您在此站点上的某些自定义有关,因为
Get-PnPSiteTemplate
没有任何参数将导出整个站点的模板(包括列表,还有所有其他内容,例如一些您可能没有的自定义应用程序)允许这样做)您可以尝试的另一件事是运行 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"
推荐阅读
- c# - 如何使用 Microsoft Graph api 或类似的 api 获取联系人组
- events - ExtJS 在禁用的 TextField 上单击事件
- puppet - 一切完成后或 exec 完成后执行 create_resource
- azure - 无法获取 Azure Devops Workitem 布局
- sql-server - 为什么我的测试环境上的查询执行计划与实时服务器不同?
- powershell - 无法使用 powershell 在 windows server 2016 上启动 windows 服务
- php - 根据数据库中的值制作表格行背景颜色
- c++ - 为什么输出不在控制台输出 C++ 中打印
- jquery - 如何显示来自 JSON 数据的匹配字符串的长度?
- python - 如果发现输入的特殊字符或数字,如何使此代码不加密消息?