首页 > 解决方案 > Connect-PowerBiServiceAccount 无法与服务主体连接

问题描述

我正在使用 Powershell 的 MicrosoftPowerBIMgmt 模块连接到 Power BI,以便我可以上传报告,但无法成功连接。我曾尝试在 Windows 10 企业机器和运行 powershell 内核的 mac 上使用此代码。
我正在尝试使用以下代码使用服务主体进行连接:

 $applicationId = "XXX"
$securePassword = "XXX" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "XXX"

我收到以下错误

WARNING: (False) MSAL 4.25.0.0 MSAL.NetCore Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 [11/15/2021 14:34:38 - 677c9e5e-9df6-4912-bdd3-994f59c64646] Fetching a new AT failed. Is AAD down? False. Is there an AT in the cache that is usable? False
    WARNING: (False) MSAL 4.25.0.0 MSAL.NetCore Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 [11/15/2021 14:34:38 - 677c9e5e-9df6-4912-bdd3-994f59c64646] Either the exception does not indicate a problem with AAD or the token cache does not have an AT that is usable.
    WARNING: (False) MSAL 4.25.0.0 MSAL.NetCore Darwin 20.5.0 Darwin Kernel Version 20.5.0: Sat May  8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 [11/15/2021 14:34:38 - 677c9e5e-9df6-4912-bdd3-994f59c64646] Exception type: Microsoft.Identity.Client.MsalServiceException
    , ErrorCode: invalid_client
    HTTP StatusCode 401

标签: powershellazure-active-directorypowerbi

解决方案


我测试过,它对我来说工作正常。如果我使用 SecurePassword 的密码而不是客户端密码,我会遇到同样的错误。

在此处输入图像描述

您可以使用新的客户端密码创建您的应用程序密钥。

在此处输入图像描述

$applicationId = "your application Client ID"
$securePassword = " application Cleint secret value " | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount  -ServicePrincipal -Credential $credential -TenantId "Your tenant ID"

输出 - - 在此处输入图像描述


推荐阅读