Using PowerShell and the Power BI REST API

Published by Thomas foster on


I think that the Power BI REST API is one of the most overlooked features of Power BI. It is an immensely powerful tool that can save you a lot of time when it comes to maintaining a large number of reports. Especially if you do not have access to some of the admin tools within your organisation.

While a REST API can look like an intimidating task it is far easier than you may think to get up and running with the API.

First a tiny bit of background, you can read very technical and wordy definitions on what a REST API truly is but I will summarise it quickly here. A REST API is a way to send requests between systems, in this case to These requests in general can be split into two types either be to tell the system to do something or to send us something. You do not have to use PowerShell to integrate with the REST API, you can use any language which supports web requests.


In order to get setup from the Power BI standpoint you need to register an App, there is a very good blog post on this by Radacad so I recommend you go over there set that up then come back to this post. Once you have that setup make sure you have your client id as this is how Power BI will know to authenticate you in order to use the API.

The next step is to install what is called the AzureRm cmdlet. All you need to know is that this lets us connect to Azure and authenticate into Power BI. To do this you need to launch PowerShell as an administrator, if you are on Windows 7+ you will already have it installed. If you are on Mac or Linux you can install it manually, if you are on Windows Vista you should consider upgrading and getting out of 2007.

To launch it search for it in the windows bar and click run as administrator. Once you have PowerShell launched you should have a nice blue window

The PowerShell terminal

Next we are going to install the cmdlet, this can be done by navigating to this PowerShell Gallery link then copying the Install Module command. It should look something like “Install-Module -Name AzureRM”. Once you have this paste it into PowerShell, follow through the prompts till it is installed. Once this has gone all the way through you now have everything installed to use the REST APIs through PowerShell.

The scripts

For this post I will cover just two useful scripts that deal with setting up refreshes for datasets in The first lets you easily set the refresh schedule of a dataset. Of course you can do this directly in the service which is fine if you have one dataset and one refresh time. However, if you need to set several datasets to refresh 48 times a day it can take a long time and a lot of clicks to set it up.
The second will stagger the refreshes of datasets within a workspace over a 24 hour period.

To start using the scripts first you need to download them from GitHub, all these scripts are located here and any future changes or new scripts will be shared there as well.
Next you need to make some slight edits to the scripts. You can either do this with just a text editor like notepad or using more advanced editors like
VS Code (what I use) or the inbuilt ISE.
Once you have the file open, fill in the parameters such as workspace id, dataset id etc. You also need to put your client id in the line where it says

$clientId = "" 

Insert your client id between the quotes, once this and all the needed parameters are filled in you should be able to run these scripts and they should change your refresh schedules accordingly.

Troubleshooting and further info

A common error that people get is

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Program Files\WindowsPowerShell\Modules\AzureRM.profile\5.8\Microsoft.IdentityModel.Clients.ActiveDirectory.dll' or one 
of its dependencies. The system cannot find the file specified.

If you get this error, make sure the cmdlet paths in the script are correct. Where it says

    $adal = "${env:ProgramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.8\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
    $adalforms = "${env:ProgramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.8.2\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"

Navigate to that location and check that the files are present. If you are reading this in the future make sure that the version number in the path “…ofile\5.8.2\Micro…” is correct. As if you have a newer version installed you will no longer be on version 5.8.2.

You can find more scripts for the REST API, which these scripts were based on, on the Azure-Samples github. Make sure you check these out as you may also find these useful.

If you have any feedback, questions, either about this post or the Power BI REST API in general, please leave me a comment below and I will endeavour to get back to you.


Bernadine · 2021-08-31 at 13:44

Hello would you mind letting me know which webhost you’re working
with? I’ve loaded your blog in 3 completely different web browsers and I must say
this blog loads a lot quicker then most. Can you suggest a good web hosting provider at a honest price?

Kudos, I appreciate it!

    Thomas foster · 2021-08-31 at 13:55

    I use wordpress hosted on site grounds

Latonya · 2021-08-28 at 16:27

Can you tell us more about this? I’d want to find out some additional information.

witaminy do włosów · 2019-09-15 at 06:20

I’m truly enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more pleasant for me
to come here and visit more often. Did you hire out
a developer to create your theme? Exceptional work!

Leave a Reply

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