简体   繁体   English

创建了 Powershell 并使用 Invoke-PowerBIRestMethod 来安排 Power BI Refresh 但引发 403 错误

[英]Created Powershell and using Invoke-PowerBIRestMethod to schedule Power BI Refresh but throws 403 error

I am using below code.我正在使用下面的代码。 I have replaced the credentials and other GUIDs with XXXX.我已经用 XXXX 替换了凭据和其他 GUID。 Please let me know if I am missing anything.如果我遗漏了什么,请告诉我。 The Service principal has read/write perms on Datasets, Reports and Workspaces as mentioned by my security team.正如我的安全团队所提到的,服务主体对数据集、报告和工作区具有读/写权限。

Connect-PowerBIServiceAccount -ServicePrincipal -CertificateThumbprint XXXX -ApplicationId XXXX -Tenant XXXX 

$jsonbody = '{
  "value": {
    "days": [
      "Sunday",
      "Tuesday",
      "Friday",
      "Saturday"
    ],
    "times": [
      "07:00",
      "11:30",
      "16:00",
      "23:30"
    ],
    "localTimeZoneId": "UTC",
    "enabled": true
  }
}'

Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/groups/XXXX/datasets/XXXX/refreshSchedule' -Method PATCH -Body $jsonbody -ContentType application/json

Resolve-PowerBIError -Last

The above script throws below error上面的脚本抛出以下错误

Powershell 错误

服务负责人的权限

After a ticket with Microsoft product team, I was able to crack the issue.在与 Microsoft 产品团队取得联系后,我能够破解该问题。

The first issue is that the Service Principal should be "Application permissions" type and not "Delegated".第一个问题是服务主体应该是“应用程序权限”类型而不是“委托”类型。 The Delegated Service Principal will throw 400 error.委托服务主体将抛出 400 错误。

The second part and the main reason for 403 - Forbidden error is that I need to takeover the dataset.第二部分,403 - Forbidden 错误的主要原因是我需要接管数据集。 It means that I shouldn't just be the admin of the Workspace but I need to first takeover dataset using Power BI REST API.这意味着我不应该只是工作区的管理员,我需要首先使用 Power BI REST API 接管数据集。 After taking over only, I can perform other dataset related tasks with Service Principal authentication.接管后,我可以使用服务主体身份验证执行其他与数据集相关的任务。

Overall the sequence will be总体顺序将是

  1. Takeover Dataset收购数据集
  2. Bind Data Gateway . 绑定数据网关 (Service Principal will require access to this Data Source in the Gateway. There are many steps for this piece to work) (服务主体将需要访问网关中的此数据源。这部分工作有很多步骤)
  3. Update Parameters (if any) 更新参数(如果有)
  4. Update Refresh Schedule 更新刷新计划

If anyone is trying something similar, then I have posted a blog with detailed implementation and steps including Powershell script here .如果有人试图类似的东西,那么我已经发布了详细的实施和步骤,包括PowerShell脚本一个博客在这里

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM