繁体   English   中英

使用Powershell刷新Power BI数据集

[英]Power BI dataset refresh using Powershell

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

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

使用以下内容,您可以轻松访问组信息:

$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.com/apps创建的“本地” AAD客户端的ID

要发送刷新命令,请使用Urls:

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

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

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

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

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

$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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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