简体   繁体   English

具有应用程序权限的 PnP Powershell Sharepoint:远程服务器返回错误:(403)禁止

[英]PnP Powershell Sharepoint with app permissions: The remote server returned an error: (403) Forbidden

I'd like to use PnP Powershell for provisioning modern Sharepoint Online sites by making a copy of an existing site in the tenant.我想使用 PnP Powershell 通过在租户中复制现有站点来配置现代 Sharepoint 在线站点。 I'm running the SharePointPnPPowerShellOnline module, version 3.22.2006.2.我正在运行 SharePointPnPPowerShellOnline 模块,版本 3.22.2006.2。

If I connect using the -UseWebLogin option like this:如果我使用-UseWebLogin选项进行连接,如下所示:

Connect-PnPOnline -Url https://<tenant>.sharepoint.com/sites/<sitename> -UseWebLogin

…and then run …然后运行

Get-PnPProvisioningTemplate -Out file.xml

…then everything works fine, and I can then go on to provision a new site from the XML file that it creates. …然后一切正常,然后我可以 go 从它创建的 XML 文件中配置一个新站点。

What I'd like to do, however, is to use Application Permissions with a Registered App in Azure AD.但是,我想做的是使用 Azure AD 中的注册应用程序的应用程序权限。 I've registered an app, and given it every Sharepoint-related permission I can think of (with a view to cutting permissions back to the minimum once I've got it working).我已经注册了一个应用程序,并授予它我能想到的所有与 Sharepoint 相关的权限(以期在我开始工作后将权限降至最低)。 I connect like this:我这样连接:

connect-PnPOnline -ClientID "<ClientID>" -ClientSecret "<ClientSecret>" -url https://<tenant>.sharepoint.com/sites/<sitename>

... and it appears to make the connection with no issues. ...而且它似乎可以毫无问题地建立联系。 However, when I try to run the following:但是,当我尝试运行以下命令时:

Get-PnPProvisioningTemplate -Out file.xml

…it fails with the error: …它失败并出现错误:

Get-PnPProvisioningTemplate : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ Get-PnPProvisioningTemplate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPProvisioningTemplate], WebException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Site.GetProvisioningTemplate

The permissions I gave my Azure AD Registered App are:我给我的 Azure AD 注册应用程序的权限是:

  • Microsoft Graph: Directory.ReadWrite.All Microsoft Graph:Directory.ReadWrite.All
  • Microsoft Graph: Group.Create Microsoft Graph:Group.Create
  • Microsoft Graph: Group.ReadWrite.All Microsoft Graph:Group.ReadWrite.All
  • Microsoft Graph: Sites.FullControl.All Microsoft Graph:Sites.FullControl.All
  • Microsoft Graph: Sites.Manage.All Microsoft Graph:Sites.Manage.All
  • Microsoft Graph: Sites.Read.All Microsoft Graph:Sites.Read.All
  • Microsoft Graph: Sites.ReadWrite.All Microsoft Graph:Sites.ReadWrite.All
  • Sharepoint: Sites.FullControl.All Sharepoint:Sites.FullControl.All
  • Sharepoint: Sites.Manage.All Sharepoint:站点.管理.全部
  • Sharepoint: Sites.Read.All Sharepoint: Sites.Read.All
  • Sharepoint: TermStore.Read.All Sharepoint:TermStore.Read.All
  • Sharepoint: TermStore.ReadWrite.All Sharepoint:TermStore.ReadWrite.All
  • Sharepoint: User.Read.All Sharepoint:User.Read.All
  • Sharepoint: User.ReadWrite.All Sharepoint:User.ReadWrite.All

I also tried creating a Sharepoint App Principal according to this article: https://www.sharepointdiary.com/2019/03/connect-pnponline-with-appid-and-appsecret.html .我还尝试根据这篇文章创建 Sharepoint 应用程序主体: https://www.sharepointdiary.com/2019/03/connect-pnponline-with-appid-and-appsecret.ZFC356FDC70D2FCA679D If I use the Client ID and Client Secret from this in my connect-PnpOnline line, again I can connect with no issues.如果我在我的connect-PnpOnline行中使用此客户端 ID 和客户端密码,我可以再次毫无问题地连接。 But again I get the same error when trying to run Get-PnPProvisioningTemplate .但是在尝试运行Get-PnPProvisioningTemplate时,我又遇到了同样的错误。

I've also tried connecting to a different site within the same tenant, and I get the same error with all of them.我还尝试连接到同一租户内的不同站点,但我都遇到了同样的错误。

I'm starting to run out of ideas on this - can anyone shed some light, please?我开始对此没有任何想法 - 任何人都可以解释一下吗?

Got it working.得到它的工作。

When I created my Sharepoint App Principal, I'd granted it permissions with this XML:当我创建我的 Sharepoint 应用程序主体时,我已通过此 XML 授予它权限:

<AppPermissionRequests AllowAppOnlyPolicy="true">
       <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>

But what I needed was:但我需要的是:

<AppPermissionRequests AllowAppOnlyPolicy="true">
       <AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
</AppPermissionRequests>

...in other works FullControl for the whole tenant, not just SiteCollection. ...在其他作品中为整个租户提供 FullControl,而不仅仅是 SiteCollection。

You can also register the app on Azure AD.您也可以在 Azure AD 上注册该应用程序。 if in that case, you need to configure a Certificate and grant permission to SharePoint API instead of MS Graph.如果在这种情况下,您需要配置证书并授予 SharePoint API 而不是 MS Graph 的权限。

在此处输入图像描述

Below is the tutorial:下面是教程:

BR BR

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell - Sharepoint 自动文件上传返回“远程服务器返回错误:(403) 禁止。” 错误 - Powershell - Sharepoint Auto file upload returning "The remote server returned an error: (403) Forbidden." error Invoke-RestMethod:远程服务器返回错误:(403) Forbidden PowerShell - Invoke-RestMethod : The remote server returned an error: (403) Forbidden PowerShell Connect-PnPOnline:远程服务器返回错误:(403)禁止 - Connect-PnPOnline : The remote server returned an error: (403) Forbidden Sharepoint 使用 powershell pnp 对文件夹的权限 - Sharepoint permissions to folders using powershell pnp 远程服务器返回错误:(403) Forbidden。 在 C:\\Program Files\\WindowsPowerShell\\Modules\\CosmosDB\\3.1.0.293\\CosmosDB.psm1 - The remote server returned an error: (403) Forbidden. At C:\Program Files\WindowsPowerShell\Modules\CosmosDB\3.1.0.293\CosmosDB.psm1 Powershell:使用 REST API 从 Sharepoint 列表中删除项目 - 远程服务器返回错误:(400) 错误请求 - Powershell: Using REST API to Delete Items from a Sharepoint List - The remote server returned an error: (400) Bad Request Powershell PnP Sharepoint - Powershell PnP Sharepoint Pnp PowerShell 更新 SharePoint 查找列时出错 - error with Pnp PowerShell updating SharePoint look up column SharePoint Pnp PowerShell日期查询 - SharePoint Pnp PowerShell date query PowerShell 脚本返回“远程服务器返回错误:(401) 未经授权” - PowerShell script return "The remote server returned an error: (401) Unauthorized"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM