[英]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.