要求:通过服务主体使用 Powershell 脚本更新 PowerBI 数据集计划。使用了 PowerBI API。参考:微软文档
错误消息:“消息”:“应用程序无法访问 API”
我做了什么:
将 SP 放入 AD 组中。将此 AD 组设为 Power BI 工作区和数据集的管理员(在 Power BI 管理员设置下)
使用使用服务主体生成的访问令牌。用于 API 请求的 Invoke-RestMethod。
$SecPasswd = ConvertTo-SecureString $ClientSecret -AsPlainText -Force $ClientCred = New-Object System.Management.Automation.PSCredential($ClientId,$SecPasswd) Connect-PowerBIServiceAccount -Tenant $tenantId -ServicePrincipal -Credential $ClientCred $accessToken = Get-PowerBIAccessToken $authHeader = @{'Content-Type'='application/json','Authorization'= $accessToken.Authorization} $uri="https://api.powerbi.com/v1.0/myorg/datasets/$datasetId/refreshSchedule" Invoke-RestMethod -Uri $uri –Headers $authHeader –Method Patch -Body ($jsonBase | ConvertTo-Json) -ContentType "application/json"
观察:
使用我工作区的 datasetId 并运行脚本。2 场景:
- 在授权标头中使用服务主体访问令牌。得到 -
Forbidden 403 Error. "Message":"API is not accessible for application。 - 在授权标头中使用我的用户凭据生成的访问令牌时,脚本成功运行。
- 在其他工作区尝试了各种数据集
我缺少哪些权限来使用服务主体更新数据集计划?
