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