Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
Hi @adild2k ,
Based on my research, you could refer yo below blog to check if your steps is correct with the tutorial:
Regards,
Daniel He
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
Still waiting for the feedback ...................
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
135 | |
117 | |
101 | |
71 | |
61 |