简体   繁体   中英

How to start Power BI Dataset refresh with SQL Agent Job

In a certain requirement I have to start Power BI Dataset refresh only after SQL Agent job finished. My plan is to add a step in the Agent Job so that it can call the Power BI Data refresh. Any one has any idea how to achieve that.

Thanks in advance.

One step to do this is with with PowerShell. Install Microsoft Power BI Management CmdLets and add a PowerShell step to execute the following script:

Import-Module MicrosoftPowerBIMgmt
Import-Module MicrosoftPowerBIMgmt.Profile

$password = "xxxxx" | ConvertTo-SecureString -asPlainText -Force
$username = "xxxxx@yyyyy.com" 
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Connect-PowerBIServiceAccount -Credential $credential

Invoke-PowerBIRestMethod -Url 'groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/datasets/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/refreshes' -Method Post

Disconnect-PowerBIServiceAccount

It will call the Refresh Dataset In Group REST API to initiate a dataset refresh.

Replace the x-es with the group/workspace ID and actual dataset ID. Also provide valid credentials. This is the simplest way, but you can also make it work with service principal for example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM