powershell 检查PowerBI工作区中是否存在应用程序

yshpjwxd  于 12个月前  发布在  Shell
关注(0)|答案(1)|浏览(157)

我正在使用以下API从PowerBI工作区检索应用程序。虽然我可以通过用户界面确认它们的存在,但在尝试通过API获取它们时遇到了问题。

# Create the HTTP request
$ListAppsResponse = Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/apps" -Headers $headers -Method Get

# Filter the apps by workspaceId
$appsInWorkspace = $ListAppsResponse.value | Where-Object { $_.workspaceId -eq $workspaceId }

$updateAppInTargetWorkspace = Get-AppsList -workspaceId $workspaceId -accessToken $accessToken

字符串
但是在使用SP时,我遇到了以下错误:
调用-RestMethod:{“消息”:“应用程序无法访问API”}
根据Microsoft的文档,我已将App.Read.All权限授予用于身份验证的服务主体。我确信SP有权访问PowerBI,因为同一SP也用于部署数据集、报告以及更新参数和连接。
下面是API权限的屏幕截图。
x1c 0d1x的数据

muk1a3rh

muk1a3rh1#

如本MS文档中所述,不支持通过API列出Power BI已安装应用的服务主体身份验证
当我在我的环境中运行你的PowerShell脚本时,我也得到了相同的错误如下:

$AppId = "appId"
$AppSecret = "client_secret"
$tenantID = "tenantId"
$workspaceId = "workspaceId"

$credentials = New-Object System.Management.Automation.PSCredential ($AppId, (convertto-securestring $AppSecret -asplaintext -force))
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credentials -Tenant $tenantID

# Get the access token from the authenticated session 
$accessToken = Get-PowerBIAccessToken
$accessToken = $accessToken.Values
$headers = @{  
       "Authorization" = "$accessToken"     
       "Content-Type" = "application/json"  
       }

# Create the HTTP request
$ListAppsResponse = Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/apps" -Headers $headers -Method Get

# Filter the apps by workspaceId
$appsInWorkspace = $ListAppsResponse.value | Where-Object { $_.workspaceId -eq $workspaceId }

字符串

回复:


的数据
解决错误,您需要以用户身份连接Power Bi帐户,而不是以服务主体身份连接。
在我的例子中,我通过传递用户的凭据修改了脚本,并以用户身份连接到Power Bi帐户,如下所示:

$username = "[email protected]"
$password = "xxxxxxxxxx"

$credentials = New-Object System.Management.Automation.PSCredential ($username, (convertto-securestring $password -asplaintext -force))
Connect-PowerBIServiceAccount -Credential $credentials

# Get the access token from the authenticated session 
$accessToken = Get-PowerBIAccessToken
$accessToken = $accessToken.Values
$headers = @{  
       "Authorization" = "$accessToken"     
       "Content-Type" = "application/json"  
       }

# Create the HTTP request
$ListAppsResponse = Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/apps" -Headers $headers -Method Get

回复:



当我运行**$ListAppsResponse.value时,我在响应**中成功获得了安装的应用列表,如下所示:


相关问题