我有一堆存储帐户,它们都保存着类似的数据,但来自不同的环境,并且我正在尝试以自动方式为每个存储帐户生成一份报告。我有一个
PBIX
文件,其中包含我需要的转换和视觉效果。
我尝试通过 PowerShell 利用 PowerBI API 基于该 PBIX 文件创建多个报告(这可行),然后更改与报告关联的数据集中的数据源以指向新的存储帐户。然而,这就是我遇到问题的地方。根据 docs 它应该相当简单,但我收到了这个模糊的错误:
参数更新详细信息丢失或无效。
我已经使用 get 方法进行了一些搜索和逆向工程,据我所知,我的
UpdateDetails
有效负载应该是有效的。
这是我正在运行的代码:
# Path to my pbix file.
$pbixPath = "C:\path\to\my\demo.pbix"
# List of storage accounts with valid sas tokens.
$storageAccounts = @(
@{"AccountName"= "account1"; "SasToken"="validSas"},
@{"AccountName"= "account2"; "SasToken"="validSas"},
@{"AccountName"= "account3"; "SasToken"="validSas"}
)
# Get the workspace
$workspaceObject = ( Get-PowerBIWorkspace -Name "my workspace" )
$groupid = $workspaceObject.id
foreach($storageAccount in $storageAccounts){
$reportName = $storageAccount.AccountName.Replace("reporting", "")
Write-Host "Publishing $reportName"
# Publish the report based on our pbix file.
$result = New-PowerBIReport -Path $pbixPath -Name $reportName -Workspace $workspaceObject -ConflictAction CreateOrOverwrite
# Get the dataset associated with the newly published report.
$dataset = Get-PowerBIDataset -Workspace $workspaceObject | Where-Object {$_.Name -eq $reportName}
$datasetid = $dataset.id
# Getting the storage account name currently used by the report's dataset.
# This account is inherited from the pbix file and needs to be overwritten with $storageAccount.AccountName.
$DefaultStorageAccount = (Invoke-PowerBIRestMethod -Method GET -Url "datasets/$DataSetId/datasources" | convertfrom-json).value.connectionDetails.account
# Preparing the body of our request to point to a new storage account
$body = @"
{
"updateDetails": [
{
"datasourceSelector": {
"datasourceType": "AzureBlobs",
"connectionDetails": {
"account": "$DefaultStorageAccount",
"domain": "blob.core.windows.net"
}
},
"connectionDetails": {
"account": "$($storageAccount.AccountName)",
"domain": "blob.core.windows.net"
}
}
]
}
"@
# Attempting to point the dataset to a new storage account. This is where the error is thrown.
Invoke-PowerBIRestMethod -Url "datasets/$DataSetId/Default.UpdateDatasources" -Method Post -Body $body
}
我尝试更新与 PowerBI 报表关联的数据集以使用新的存储帐户。我希望这个 API 调用能够毫无问题地被接受,但模糊的错误与文档不符。
尝试添加:
-ContentType "application/json"
作为附加参数。
如果失败,可能是此 API 调用不支持“AzureBlobs”。来自文档:
限制
仅支持以下数据源:SQL Server、Azure SQL Server、Azure Analysis Services、Azure Synapse、OData、SharePoint、Teradata 和 SAP HANA。对于其他数据源,请使用更新组中参数 API 调用。