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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
adild2k
Frequent Visitor

Refreshing Power BI dataset from an on-premise Power Shell script

How to refresh Power BI dataset from an on-premise Power Shell script? I am trying but somehow the dataset is not get updated.

 

I am attaching the power shell script;

 

# This sample script calls the Power BI API to progammtically trigger a refresh for the dataset
# It then calls the Power BI API to progammatically to get the refresh history for that dataset
# For full documentation on the REST APIs, see:
# Instructions:
# 2. Set up a dataset for refresh in the Power BI service - make sure that the dataset can be
# updated successfully
# 3. Fill in the parameters below
# 4. Run the PowerShell script

# Parameters - fill these in before running the script!
# =====================================================

# An easy way to get group and dataset ID is to go to dataset settings and click on the dataset
# that you'd like to refresh. Once you do, the URL in the address bar will show the group ID and
# dataset ID, in the format:
# app.powerbi.com/groups/{groupID}/settings/datasets/{datasetID}

$groupID = "" # the ID of the group that hosts the dataset. Use "me" if this is your My Workspace
$datasetID = "" # the ID of the dataset that hosts the dataset

# AAD Client ID
# To get this, go to the following page and follow the steps to provision an app
#
# To get the sample to work, ensure that you have the following fields:
# App Type: Native app
# Redirect URL: urn:ietf:wg:oauth:2.0:oob
# Level of access: all dataset APIs
$clientId = ""
# $clientId = ""

# End Parameters =======================================

# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD
function GetAuthToken
{
$adal = "${env:ProgramFiles}\WindowsPowerShell\Modules\AzureRM.profile\5.8.3\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"

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

[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null

[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null

$redirectUri = "urn:ietf:wg:oauth:2.0:oob"

$resourceAppIdURI = ""

$authority = "";

$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority

# New line so that the dialog box will not appear
$UserCred = New-Object “Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential” -ArgumentList ““, “”

$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")

return $authResult
}


# Get the auth token from AAD
$token = GetAuthToken

# Building Rest API header with authorization token
$authHeader = @{
'Content-Type'='application/json'
'Authorization'=$token.CreateAuthorizationHeader()
}

# properly format groups path
$groupsPath = ""
if ($groupID -eq "me") {
$groupsPath = "myorg"
} else {
$groupsPath = "myorg/groups/$groupID"
}

# Refresh the dataset
#$uri = ""
#POST
#Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST –Verbose

# Check the refresh history
$uri = ""
$payload = Invoke-RestMethod -Uri $uri –Headers $authHeader –Method GET –Verbose | ConvertTo-Json |
ConvertFrom-Json |
Select -ExpandProperty value |
Select id, refreshType, startTime, endTime, status

4 REPLIES 4
v-danhe-msft
Employee
Employee

Hi @adild2k ,

Based on my research, you could refer yo below blog to check if your steps is correct with the tutorial:

https://blogs.solidq.com/en/businessanalytics/how-to-refresh-power-bi-dataset-from-an-on-premise-pow...

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, Thanks for the response . I have followed the link earlier with some other links too. 

 

I have figured it out earlier the issue, as there were some of the snippets which were remarked in the code. It is working correctly now. Becuase of this my dataset is being updated properly but the Power BI Report is not get updated, on the other hand Power BI Dashboard is getting updated. Is there a way that a Power Report published on Power BI Service will get updated after every 15 mins? We are currently using Power BI Pro license.

 

Regards

 

 

Hi @adild2k ,

You could refer to below link about rest API for the schedule refresh, but I am afraid you could not refresh every 15 minutes:

https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/getrefreshschedule

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Still waiting for the feedback ...................

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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