To all the data scientists, here is the quick code in PowerShell to automate your PowerBI reports and Dashboard refresh.
Import the Power BI module
Import-Module -Name MicrosoftPowerBIMgmtConnect to the Power BI service
Connect-PowerBIServiceAccountGet the list of Power BI files in the workspace
$workspaceId = “” $workspace = Get-PowerBIWorkspace -Scope Organization -Id $workspaceId $datasets = Get-PowerBIDataset -Scope Workspace -WorkspaceId $workspace.IdRefresh each dataset
foreach($dataset in $datasets) { Refresh-PowerBIDataset -Id $dataset.Id -Scope Workspace -WorkspaceId $workspace.Id }Open the Power BI Desktop file
$filePath = “” $powerBIDesktop = “$env:ProgramFiles\Microsoft Power BI Desktop\bin\PowerBIDesktop.exe” Start-Process -FilePath $powerBIDesktop -ArgumentList $filePath
Please make sure that you replace the <workspace-id>
and <path-to-pbix-file>
with the actual ID of your workspace and the path to the Power BI file you want to open, respectively. Also check if you have the Power BI power-shell module installed, if not then you will have to install it using the command Install-Module -Name MicrosoftPowerBIMgmt
.
Enjoy!
THIS POST IS WRITTEN BY SYED LUQMAN, A DATA SCIENTIST FROM SHEFFIELD, SOUTH YORKSHIRE, AND DERBYSHIRE, UNITED KINGDOM. SYED LUQMAN IS OXFORD UNIVERSITY ALUMNI AND WORKS AS A DATA SCIENTIST FOR A LOCAL COMPANY. SYED LUQMAN HAS FOUNDED INNOVATIVE COMPANY IN THE SPACE OF HEALTH SCIENCES TO SOLVE THE EVER RISING PROBLEMS OF STAFF MANAGEMENT IN NATIONAL HEALTH SERVICES (NHS). YOU CAN CONTACT SYED LUQMAN ON HIS TWITTER, AND LINKEDIN. PLEASE ALSO LIKE AND SUBSCRIBE MY YOUTUBE CHANNEL.