Publish Microsoft power bi using power shell


PowerShell Script — Publish Power BI Report to Cloud




Install Power BI PowerShell module (run once)



Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser



Login to Power BI Service



Login-PowerBIServiceAccount



Define variables



$pbixPath = “C:\Reports\SalesDashboard.pbix”

$workspaceName = “Finance Analytics”

$reportName = “Sales Dashboard”



Get workspace ID



$workspace = Get-PowerBIWorkspace -Name $workspaceName

$workspaceId = $workspace.Id



Publish report to Power BI Service



New-PowerBIReport -Path $pbixPath -Name $reportName -WorkspaceId $workspaceId -ConflictAction CreateOrOverwrite



Verify upload



Get-PowerBIReport -WorkspaceId $workspaceId



Optional — Save as reusable PowerShell script (publish_report.ps1)



param (

[string]$pbixPath,

[string]$workspaceName,

[string]$reportName

)


Import-Module MicrosoftPowerBIMgmt

Login-PowerBIServiceAccount


$workspace = Get-PowerBIWorkspace -Name $workspaceName

New-PowerBIReport -Path $pbixPath -Name $reportName -WorkspaceId $workspace.Id -ConflictAction CreateOrOverwrite


Logout-PowerBIServiceAccount



Example run command



.\publish_report.ps1 -pbixPath “C:\Reports\Finance.pbix” -workspaceName “Finance BI” -reportName “Finance Overview”



Advanced option — Use REST API directly



$token = (Get-PowerBIAccessToken).AccessToken

$workspaceId = “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”


Invoke-RestMethod -Uri “https://api.powerbi.com/v1.0/myorg/groups/$workspaceId/imports?datasetDisplayName=SalesDashboard” -Headers @{Authorization = "Bearer $token"}

-Method Post -InFile "C:\Reports\SalesDashboard.pbix"

-ContentType “application/octet-stream”




✅ Notes


  • Make sure you have permission to publish to the workspace.
  • Use -ConflictAction CreateOrOverwrite to update existing reports.
  • For automation, use service principals (App registration in Azure AD).
  • This method works for Power BI Pro and Power BI Premium workspaces.



From Blogger iPhone client