Invoke-PowerBIRestMethod:发生一个或多个错误。 (响应>状态码不表示成功:401(未经授权)

问题描述 投票:0回答:1

我尝试在 PowerShell 中获取 Power Bi 事务,但收到 401 未经授权的错误。

我首先运行命令“Login-PowerBIServiceAccount”,浏览器会自动打开以使用我的服务帐户登录。我登录并运行下面的脚本:

Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/groups/SOME-GUID/dataflows/SOME-GUID/transactions' -Method GET

然后我得到了这个错误:

Invoke-PowerBIRestMethod:发生一个或多个错误。 (回复 状态码不表示成功:401(未经授权)。)

我需要授予自己哪些权限才能运行此脚本?

powershell powerbi http-status-code-401 unauthorized
1个回答
0
投票

您需要使用 Connect-PowerBIServiceAccount 进行身份验证。

$tenantId = "xxx"

$appId = "xxx"

$clientSecret = "xxx"

$securePassword = ConvertTo-SecureString $clientSecret -Force -AsPlainText

$credential = 新对象管理.Automation.PSCredential($appId, $securePassword)

Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -Credential $credential

Invoke-PowerBIRestMethod -Url $getWorkspacesUrl -Method Get

© www.soinside.com 2019 - 2024. All rights reserved.