使用 Powershell 刷新 Power BI 数据集 [英] Power BI dataset refresh using Powershell

查看:75
本文介绍了使用 Powershell 刷新 Power BI 数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用这个 powershell 脚本来刷新 Power BI 中的数据集,这对我有用,但问题是当我运行脚本时,总是有一个弹出窗口让我登录我的 Power BI 帐户.我真的很想知道是否有办法让脚本自动登录?谢谢

I've been using this powershell script to refresh the dataset in Power BI which was worked for me, but the problem was when I ran the script there was always a pop-up for me to login to my Power BI account. I really want to know if there's anyway to make the script auto login for me? Thank You

脚本:https://github.com/Azure-Samples/powerbi-powershell/blob/master/manageRefresh.ps1

推荐答案

通过以下内容,您可以轻松访问群组信息:

With the following you can easily get access the group info:

$pbiUsername = "< USERNAME >"
$pbiPassword = "< PASSWORD >"
$clientId = "< CLIENT-ID >"

$body = @{"resource" = "https://analysis.windows.net/powerbi/api";
    "client_id" = $clientId;
    "grant_type" = "password";
    "username" = $pbiUsername;
    "password" = $pbiPassword;
    "scope" = "openid"
    }

$authUrl = "https://login.windows.net/common/oauth2/token/"
$authResponse = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body

$headers = @{
             "Content-Type" = "application/json";
             "Authorization" = $authResponse.token_type + " " + 
                                $authResponse.access_token
           }

$restURL = "https://api.powerbi.com/v1.0/myorg/groups"
$restResponse = Invoke-RestMethod -Uri $restURL –Method GET -Headers $headers

此处的 clientId 是来自使用 https://dev.powerbi 创建的本机"AAD 客户端的 ID.com/apps

Here the clientId is the Id from the 'native' AAD client created using https://dev.powerbi.com/apps

使用 Urls 发送刷新命令:

To send a refresh command one uses the Urls:

如果数据集在您自己的工作区中:

If the dataset is in your own workspace:

$datasetId = "DATASET-ID"
$restUrl = "https://api.powerbi.com/v1.0/myorg/datasets/$datasetId/refreshes"

否则,当它在组工作区中时:

Otherwise, when it is in a group workspace:

$datasetId = "DATASET-ID"
$groupId = "GROUP-ID"
$restUrl = 
 "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshes"

现在将作业发送到 powerBI 服务器:

Now send the job to the powerBI Server:

$body = @{
            "notifyOption"= "MailOnFailure"
         }

$restResponse = Invoke-RestMethod -Uri $restUrl –Method POST -Headers $headers -Body $body

另见博文:https://blog.gbrueckl.at/2017/08/refresh-powerbi-datasets-powershell-azure-runbooks/

这篇关于使用 Powershell 刷新 Power BI 数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆