Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I've got a bunch of storage accounts, all holding similar data but from different environments, and I'm trying to generate a report per storage account in an automated fashion. I've got a PBIX file that contains the transformations and visuals that I need.
I'm trying to leverage the PowerBI API via PowerShell to create multiple reports based on that PBIX file (this works) and to then change the datasource in the dataset associated with the report to point to the new storage account. However, this is where I'm running into issues. According to the docs it should be fairly straightforward, but I'm getting this vague error: "Parameter UpdateDetails is missing or invalid". I've done some searching and reverse-engineering using the get method and far as I can tell my UpdateDetails payload should be valid.
This is the code I'm running:
# 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
}
Does anyone have any clue what might be wrong with my API call, or alternatively, where to open an issue with the API?
Hi @Tim_Groothuis ,
You can refer the solution in the following link to solve it:
powerbi - How to update a data source via the API
$json =
@'
{{
"updateDetails": [{{
"datasourceSelector": {{
"datasourceType": "AnalysisServices",
"connectionDetails": {{
"server": "MY-OLD-SERVER-NAME",
"database": "MY-OLD-MODEL-NAME"
}},
"datasourceId": "{2}",
"gatewayId": "{3}"
}},
"connectionDetails": {{
"server": "{0}",
"database": "{1}"
}}
}}
]
}}
Or please update the codes as below by adding headers:
$body = @{
updateDetails = @(
@{
datasourceSelector = @{
datasourceType = "AzureBlob"
connectionDetails = @{
account = $DefaultStorageAccount
domain = "blob.core.windows.net"
}
}
connectionDetails = @{
account = $storageAccount.AccountName
domain = "blob.core.windows.net"
}
}
)
} | ConvertTo-Json -Compress
# Adding headers
$headers = @{
"Content-Type" = "application/json"
}
# Attempting to point the dataset to a new storage account. This is where the error is thrown.
Invoke-PowerBIRestMethod -Method Post -Url "datasets/$datasetId/Default.UpdateDatasources" -Headers $headers -Body $body
}
Best Regards
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
6 | |
6 | |
3 | |
2 | |
2 |