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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
g_m_j
Frequent Visitor

Problems using Invoke-PowerBiRestMethod in PowerShell

(I'm no PowerShell expert)

 

I'm trying to script PowerBI dataset refreshes using a PowerShell script and the Invoke-PowerBIRestMethod.

 

It all works fine for a single hardcoded dataset, as below:

 

 

$body = "{'notifyOption':'MailOnCompletion'}"
$result = Invoke-PowerBIRestMethod -url "https://api.powerbi.com/v1.0/myorg/datasets/xxxxxxxxxxxxxxxxxxxxxxxxxx/refreshes" -Method POST -Body $body

 

 

However, I'd like to store all my dataset IDs in a txt file, then pass these in as a variable and get the script to loop through each. This is where I'm hitting (unhelpful) errors.

 

My script is as below:

 

 

Login-PowerBI

$body = "{'notifyOption':'MailOnCompletion'}"
$Data=Import-Csv -Path "\\abc\Desktop\PBI_Dashboards_Refresh_List.txt" -Delimiter ","

foreach ($dat in $Data)

{
$result = Invoke-PowerBIRestMethod -url "https://api.powerbi.com/v1.0/myorg/datasets/$dat.WorkspaceID/refreshes" -Method POST -Body $body

}
Resolve-PowerBIError -Last

 

 

The error I'm getting is:

 

 

Message : Response status code does not indicate success: 404 (Not Found).
StackTrace : at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.<InvokeRestMethod>d__35.MoveNext()
Exception : System.Net.Http.HttpRequestException
InvocationInfo : {Invoke-PowerBIRestMethod}
Line : $result = Invoke-PowerBIRestMethod -url "https://api.powerbi.com/v1.0/myorg/datasets/$dat.WorkspaceID/refreshes" -Method POST -Body $body

Position : At line:7 char:15
+ ... $result = Invoke-PowerBIRestMethod -url "https://api.powerbi.com/v1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId : 25

 

 

Any help appreciated 🙂

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @g_m_j ,

 

According to your statement, I think 404 error should be an authentication error in Power BI. Please make sure your account has access to Power BI or have access to pass the refresh API to Power BI.

About using Powershell to refresh dataset, I think this blog could help you better to use it:

Using-the-power-bi-api-with-powershell-scripts-refreshing-your-dataset 

 

Best Regards,
Rico Zhou

 

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @g_m_j ,

 

According to your statement, I think 404 error should be an authentication error in Power BI. Please make sure your account has access to Power BI or have access to pass the refresh API to Power BI.

About using Powershell to refresh dataset, I think this blog could help you better to use it:

Using-the-power-bi-api-with-powershell-scripts-refreshing-your-dataset 

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.