Python + PowerShell | Use this simple code to auto refresh the PowerBI files

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 MicrosoftPowerBIMgmt

Connect to the Power BI service

Connect-PowerBIServiceAccount

Get the list of Power BI files in the workspace

$workspaceId = “”
$workspace = Get-PowerBIWorkspace -Scope Organization -Id $workspaceId
$datasets = Get-PowerBIDataset -Scope Workspace -WorkspaceId $workspace.Id

Refresh 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 SHEFFIELDSOUTH YORKSHIRE, AND DERBYSHIREUNITED KINGDOMSYED 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

×

Hey!

Please click below to start the chat!

× Let's chat?