Powershell 如何刷新PowerBI报告?

Powershell 如何刷新PowerBI报告?,powershell,powerbi,Powershell,Powerbi,我们正在使用以下命令尝试刷新报告: 在刷新之前,我们测试报表API是否工作良好 Invoke-RestMethod -UseDefaultCredentials -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)" -verbose 这为我们返回了一些东西,所以我们知道这部分正在工作 VERBOSE: received 946-byt

我们正在使用以下命令尝试刷新报告:

在刷新之前,我们测试报表API是否工作良好

Invoke-RestMethod -UseDefaultCredentials -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)" -verbose
这为我们返回了一些东西,所以我们知道这部分正在工作

VERBOSE: received 946-byte response of content type application/json; odata.metadata=minimal; odata.streaming=true

@odata.context      : https://pbi.dev.company.com/reports/api/v2.0/$metadata#CacheRefreshPlans/$entity
Id                  : CC1A4569-B890-9633-7H33-908762F54436
Owner               : user
Description         :
CatalogItemPath     : /Prototypes/Test/TestReport
EventType           : DataModelRefresh
Schedule            : @{ScheduleID=; Definition=}
ScheduleDescription :
LastRunTime         : 2019-09-03T17:19:18.143-04:00
LastStatus          : Data Refresh failed, contact the administrator, SessionId: 123456-874356-8738764
ModifiedBy          : user
ModifiedDate        : 2019-08-29T16:55:29.173-04:00
ParameterValues     : {} 
现在我们发现这个命令应该会刷新一个报告,但是我们看不到对报告所做的任何更改/更新,也就是说,如果我们删除数据库中的记录,它仍然会显示在报告上

Invoke-RestMethod -UseDefaultCredentials -method POST -uri "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(CC1A4569-B890-9633-7H33-908762F54436)/Model.Execute" -verbose
这将返回0字节,并且没有响应。所以我们假设Model.Execute不是正确的命令,或者我们仍然缺少一些东西

0字节负载详细:收到内容类型的0字节响应


这就是我们最终要做的,我们必须使用URI中的路径

$User = ""
$Password = "" 

$secureString = New-Object -TypeName System.Security.SecureString
$Password.ToCharArray() | ForEach-Object {$secureString.AppendChar($_)}
$Creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $User, $secureString 

# Retrieve the scheduled refresh data for a specific report and set it to a variable to get the Id value
$refreshplan = Invoke-RestMethod -UseDefaultCredentials <# -Credential $creds #> -uri "https://pbi.dev.company.com/reports/api/v2.0/PowerBIReports(path='/Prototypes/SAP%20Test/Update%20Test')/CacheRefreshPlans" 

# This is how you can reference the Id value in the results from above
$refreshplan.value.Id
$refreshplan.value.LastRunTime
$refreshplan.value.LastStatus

# Using the above Id value, create the URI string to run the Model.Execute method
try {
    $refreshuri = "https://pbi.dev.company.com/reports/api/v2.0/CacheRefreshPlans(" + $refreshplan.value.Id + ")/Model.Execute"
}
catch {$error[0]}

# Invoke the Model.Execute method to start the scheduled refresh for the PBIX report
Invoke-RestMethod -UseDefaultCredentials <# -Credential $creds #> -method POST -uri $refreshuri -verbose

# To check on the scheduled refresh status, you can update the data in $refreshplan by running the CacheRefreshPlans again
$refreshplan = Invoke-RestMethod -UseDefaultCredentials <# -Credential $creds #> -uri "https://pbi.dev.company.com/reports/api/v2.0/PowerBIReports(path='/Prototypes/SAP%20Test/Update%20Test')/CacheRefreshPlans"

# Get the LastRuntime and LastStatus values to check the status
$refreshplan.value.LastRunTime
$refreshplan.value.LastStatus

# The following SQL might be helpful for PowerBI CacheRefreshPlans/PowerBI Reports info:

# SELECT*FROM ReportServer.dbo.ReportSchedule
# SELECT*FROM ReportServer.dbo.Subscriptions
# SELECT*FROM ReportServer.dbo.Catalog