|
| 1 | +# ================================ |
| 2 | +# PowerShell Script - Import RDL into Power BI Workspace |
| 3 | +# ================================ |
| 4 | + |
| 5 | +param( |
| 6 | + [string]$TenantId = "<YOUR_TENANT_ID>", |
| 7 | + [string]$ClientId = "<YOUR_CLIENT_ID>", |
| 8 | + [string]$ClientSecret = "<YOUR_CLIENT_SECRET>", |
| 9 | + [string]$WorkspaceId = "<YOUR_WORKSPACE_ID>", |
| 10 | + [string]$RdlFilePath = "<PATH_TO_YOUR_RDL_FILE>" |
| 11 | +) |
| 12 | + |
| 13 | +# Install module if not present |
| 14 | +if (-not (Get-Module -ListAvailable -Name MicrosoftPowerBIMgmt)) { |
| 15 | + Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser -Force |
| 16 | +} |
| 17 | + |
| 18 | +Import-Module MicrosoftPowerBIMgmt |
| 19 | + |
| 20 | +# Authenticate using Service Principal |
| 21 | +$SecureSecret = ConvertTo-SecureString $ClientSecret -AsPlainText -Force |
| 22 | +$Credential = New-Object System.Management.Automation.PSCredential($ClientId, $SecureSecret) |
| 23 | + |
| 24 | +Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $TenantId -Credential $Credential |
| 25 | + |
| 26 | +# Derive report name from file |
| 27 | +$ReportName = [System.IO.Path]::GetFileNameWithoutExtension($RdlFilePath) |
| 28 | + |
| 29 | +# Check if report already exists |
| 30 | +$ExistingReport = Get-PowerBIReport -WorkspaceId $WorkspaceId | Where-Object { $_.Name -eq $ReportName -and $_.ReportType -eq "PaginatedReport" } |
| 31 | + |
| 32 | +if ($ExistingReport) { |
| 33 | + Write-Host "Report '$ReportName' already exists. Deleting for overwrite..." |
| 34 | + Remove-PowerBIReport -Id $ExistingReport.Id -WorkspaceId $WorkspaceId -Force |
| 35 | +} |
| 36 | + |
| 37 | +# Import the RDL |
| 38 | +Write-Host "Importing RDL report '$ReportName'..." |
| 39 | +Import-PowerBIReport -Path $RdlFilePath -Name $ReportName -WorkspaceId $WorkspaceId -ConflictAction CreateOrOverwrite -ImportAsPaginatedReport |
| 40 | + |
| 41 | +Write-Host "✅ RDL report '$ReportName' imported successfully." |
0 commit comments