简体   繁体   English

Power BI - 数据集刷新完成数据 PowerShell

[英]Power BI - dataset refresh completion data PowerShell

I am using PowerShell to refresh my powerbi.com datasets programmaticlly.我正在使用 PowerShell 以编程方式刷新我的 powerbi.com 数据集。 This is all working fine.这一切正常。 What would be helpful, however, is if there is a way to retrieve the refresh completion time data from Microsoft.但是,如果有一种方法可以从 Microsoft 检索刷新完成时间数据,这将是有帮助的。 I could list the process I'm using to kick off the refresh, but that is well documented and not pertinent to this question.我可以列出我用来启动刷新的过程,但这是有据可查的,与此问题无关。

Since powerbi.com shows the dataset refresh completion time, it would stand to reason that I could grab that data, but I cannot find any documentation on this.由于 powerbi.com 显示数据集刷新完成时间,因此我可以获取该数据是合理的,但我找不到任何有关此的文档。 Has anyone on here tried to grab this data (screenshot below)?这里有没有人试图获取这些数据(下面的截图)?

在此处输入图片说明

Instead of POST method, which will trigger a refresh, ie this is the Refresh Dataset In Group API, change the method to GET to use Get Refresh History In Group API.代替将触发刷新的POST 方法,即这是Refresh Dataset In Group API,将方法更改为GET 以使用Get Refresh History In Group API。 This will return information about the refreshes of this dataset.这将返回有关此数据集刷新的信息。 So the PowerShell code could be something like this:所以 PowerShell 代码可能是这样的:

Import-Module MicrosoftPowerBIMgmt

$username = "my super strong password"
$password = "user@domain.com" | ConvertTo-SecureString -asPlainText -Force

$groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$datasetId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Connect-PowerBIServiceAccount -Credential $credential

$refreshes_response = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$groupId/datasets/$datasetId/refreshes" -Method Get 

Disconnect-PowerBIServiceAccount

$refreshes_response_json = ConvertFrom-Json $refreshes_response

foreach ($refresh in $refreshes_response_json.value)
{
    Write-Output "refreshType: $($refresh.refreshType), startTime: $($refresh.startTime), endTime: $($refresh.endTime), status: $($refresh.status)"
}

You can also limit the number of refreshes returned by providing a number in the URL:您还可以通过在 URL 中提供一个数字来限制返回的刷新次数:

GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasets/{datasetId}/refreshes?$top={$top}

But if the last one is not successful, you may want to look at older events to find the last successful one.但如果最后一个不成功,您可能需要查看较旧的事件以找到最后一个成功的事件。 Also look at the status of the refresh, because it may still be in progress (it will say Unknown in such case).还要查看刷新的状态,因为它可能仍在进行中(在这种情况下它会显示Unknown )。

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

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