Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
GoingIncognito
Advocate III
Advocate III

How to use Powershell to refresh dataset in portal

Hi.

I do not come from a scripting/coding background so I've difficulties with this. How to use Powershell to refresh a dataset?
I managed to both 
1. use "Try it" here https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdatasetingroup

2. wrote PS script to return list of last refreshes of a given dataset:
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/{...}/datasets/{...}/refreshes" -Method Get

 

But how do I actually refresh a dataset? Thank you so much guys!

1 ACCEPTED SOLUTION

Ok now it's messing with us haha. How many times have you refresh the dataset today? Asking to refresh like is still count in 8 times a day limitation. If we are running the 9th, it will response 400 like now.

If you haven't refreshed 8 times today let's try adding the body (it shouldn't be that because it's not mandatory, but we don't have anything to lose)

$MailFailureNotify = @{"notifyOption"="MailOnFailure"}
Invoke-PowerBIRestMethod -Url $RefreshDSURL -Method Post -Body $MailFailureNotify

I hope this helps, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

13 REPLIES 13
ibarrau
Super User
Super User

Hi. That might be because the method should be "Post" and not "Get". I usually send this example:
https://github.com/ibarrau/PowerBi-code/blob/master/PowerShell/RefreshPowerBi.ps1

But this time I think it might be that the only missing thing if you get to that line.

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Oh I pasted the wrong line from my notepad 😄 Yeah POST for sure. 
Also, is your avatar from Goonies II or Ice climber?

Your avatar reigns supreme!


But what I got was:

GoingIncognito_0-1598616976834.pngGoingIncognito_1-1598616999144.png

I don't know what I am missing. Well powershell skillz for sure!

That's odd. Please be sure your credentials are ok. Try no using the first lines of my code for login and just use:

Connect-PowerBIServiceAccount

That will show a pop-up of microsoft login. Let's see if that give us error.

Be sure to complete the correct ids for the URL like the code in github. You can take them from Power Bi Service URL when you are in the dataset.

Regards, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Connect-PowerBIServiceAccount works fine. And the id's I've double checked from both the browser and using powershell cmdlets.

Can you show me the full picture of the error that show when you do this?

$DSIDRefresh = "XXXX-XXXX-XXXX-XXXX"
$WSIDAdmin = "XXXX-XXXX-XXXX-XXXX"
$RefreshDSURL = 'groups/' + $WSIDAdmin + '/datasets/' + $DSIDRefresh + '/refreshes'
Invoke-PowerBIRestMethod -Url $RefreshDSURL -Method Post

 That url with "groups/XXXX-XXXX-XXXX-XXXX/datasets/XXXX-XXXX-XXXX-XXXX/refreshes" should work. Don't use the one in the API doc.

Please also try another method of the cmdlet like "Get-PowerBIWorkspace". Let see if there is a problem in Rest Method or permission.

Regards

 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Get-PowerBIWorkspace works just fine.

 

 

GoingIncognito_0-1598619784154.png

 

Ok now it's messing with us haha. How many times have you refresh the dataset today? Asking to refresh like is still count in 8 times a day limitation. If we are running the 9th, it will response 400 like now.

If you haven't refreshed 8 times today let's try adding the body (it shouldn't be that because it's not mandatory, but we don't have anything to lose)

$MailFailureNotify = @{"notifyOption"="MailOnFailure"}
Invoke-PowerBIRestMethod -Url $RefreshDSURL -Method Post -Body $MailFailureNotify

I hope this helps, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Thanks for all the help, but still no success.

GoingIncognito_0-1598621315018.png

 

This should be the third update today, so no problems there. I dunnoo, I get something wrong.

 

I tried against another dataset and now it worked!

As a sidenote Adam here is doing the same thing but he uses body parameter. He doesn't show it though, I really don't understan what should go there?

https://youtu.be/ClmZ-8p6x9g?t=478

Good. Hope that works for you. Please accept the post as an answer if you make it work as expected so other users can find it easily.

It is a custom paint creation I made from Ice Climbers 🙂

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

GoingIncognito
Advocate III
Advocate III

Am I missing something like:
-ContentType "application/json" -Headers

and after "-Headers" I'd use some notation to give bearer token?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.