Forum Discussion
Getting the PbiServiceModelId so we can change the dataset against a report (pbix file).
I have the same issue.
Anyone has a solution here?
Anyone knows what the PbiServiceModelId exactly is?
What i found out:
If you change the datasetID and open the pbix file again it is reestablishing the connection to the PBIService and after saving the PbiServiceModelId is changed.
But I do not know how to get the id via API.
Currently there is no straight forward approach to retrieve PbiServiceModelId(numeric digit) using API.
There are multiple workarounds you could try to do the automation. I have followed below mentioned approach.
1. Deploy Model.pbix to pbi service.
2. Login to powerbi.com to grab the PbiServiceModelId. After logging in navigate to any workspaces, it makes a call to SharedDatasets to fetch all datasets. You could grab the right one.
3. You can use below ZipUnZip function to update the connection.
function Set-DatasetId([string] $directoryPath, [string] $reportName)
{
$zipFileName = "$($directoryPath)\$($reportName).zip"
$pbiFileName = "$($directoryPath)\$($reportName).pbix"
Copy-Item $pbiFileName $zipFileName -Force
$unZippedirname = "$($directoryPath)\$($reportName)"
Expand-Archive -Path $zipFileName -DestinationPath $unZippedirname -Force -Verbose
Write-Host "$($directoryPath)\$($reportName)"
$securityBindingsFileName = "$($unZippedirname)\SecurityBindings"
Remove-Item -Path $securityBindingsFileName -Force -ErrorAction SilentlyContinue
$connectionFileName = "$($unZippedirname)\Connections"
$fileContent = (Get-Content -Raw $connectionFileName) -replace $global:orgdatasetId, $global:PPACModelDatasetId
$fileContent = $fileContent -replace $global:orgModelId , $PpacModelId
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($connectionFileName, $fileContent, $Utf8NoBomEncoding)
$contentTypesFileName = "$($unZippedirname)"
Get-ChildItem "$contentTypesFileName" -Filter *.xml | Sort-Object -desc |
Foreach-Object {
$contentTypeorg= $_.Name
$filenameExracted= $_.Name.Replace("[","``[").Replace("]","``]")
if ($filenameExracted -eq "``[Content_Types``].xml")
{
$filenameExracted= $contentTypesFileName+'\'+ $filenameExracted
$fileContent = (Get-Content -Raw $filenameExracted) -replace '<Override PartName="/SecurityBindings" ContentType="" />', ''
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
#[System.IO.File]::WriteAllLines($_.FullName, $fileContent, $Utf8NoBomEncoding)
}
}
$ZipDirName = "$($unZippedirname)\*"
Compress-Archive -Path $ZipDirName -DestinationPath $zipFileName -Update -Verbose
Remove-Item -Path $pbiFileName -Force -ErrorAction SilentlyContinue -Verbose
Copy-Item $zipFileName $pbiFileName -Force -Verbose
Write-Host "PowerBI file $($reportName) are updated with dataset"
}