Invoke-PowerBIRestMethod to run paginated reports returns empty results

62 views Asked by At

How to loop through a test of all the paginated reports in a PBI Online Workspace, open each report, and then close the report, first as a user with Member permissions, then as a user with Viewer permissions?

    <#
    # 
    
    $PSVersionTable
    
        Name                           Value
        ----                           -----
        PSVersion                      5.1.19041.3031
        PSEdition                      Desktop
        PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
        BuildVersion                   10.0.19041.3031
        CLRVersion                     4.0.30319.42000
        WSManStackVersion              3.0
        PSRemotingProtocolVersion      2.3
        SerializationVersion           1.1.0.1
    #>

    Login-PowerBI -Environment USGov
    #Login with MSOffice CurrentUser.  CurrentUser is an Admin of the PBI DEV_Workspace.
    <#
    
    $reporturl = [ a URL that runs the Test Report, which opens and is then available for Export via the Export menu that appears after the report is run ]
    $rID = [ id of the report used in $reporturl ]

The following is a Powershell test script run as CurrentUser (not Admin) showing the empty result responses in various fields tested. Results show that any form of change has not been found.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Run the report
<#
Test Report runs without parameters in the DEV_Workspace ]

$reporturl = [ a URL that runs the Test Report that runs successfully, and then is available for Export via the Export menu that appears after the report is run.]
$rID = [ the guid of the report used in $reporturl ]
#>


Write-Output "Run Report"   

$body = "{`"format`": `"pdf`"}"
Write-Output "Body $Body"           
write-output "URL $($reporturl)"

Try
{
    $Export = Invoke-PowerBIRestMethod -Url $reporturl -Method POST -Body $Body 
    #Resolve-PowerBIError -Last
}
Catch
{
    Write-Output "POST Catch: $($_.Exception.Message)"
    Resolve-PowerBIError -Last
    break
}



#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# While loop to wait for report to run
write-output "Run Tests of base reporturl"

$ex = 0
while ($ex -eq 0) {
    Start-Sleep -Seconds 30
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Retrieve the export status to control the while loop
    write-output "WAITED 30 Seconds for [reporturl]"
    Try
    {
        $response = Invoke-PowerBIRestMethod -Url $reporturl -Method GET 
    }
    Catch
    {
        Write-Output "GET Catch: $($_.Exception.Message)"
        Resolve-PowerBIError -Last
        #break
    }

    
    if ($response.value -eq "") {
        Write-Output "response value is empty"
    } else {
            Write-Output "Value >$($response.value)<"
    }
    if ($response.StatusCode -eq "") {
        Write-Output "response StatusCode is empty"
    } else {
            Write-Output "StatusCode >$($response.StatusCode)<"
    }

    if ($response.record -eq "") {
        Write-Output "response record is empty"
    } else {
            Write-Output "Record >$($response.record)<"
    }

    if ($response.record.tables -eq "") {
        Write-Output "response record.tables is empty"
    } else {
            Write-Output "Mappings >$($response.record.tables)<"
    }
    
    if ($response.psobject.Properties.Name -eq "") {
        Write-Output "Report psobject Property Name is empty"
    }
    else {
        Write-Output "> $($response.psobject.Properties.Name) <"
        if ($Report.psobject.Properties.Name.Length -eq "") {
            Write-Output "response psobject Property Name Length is empty"
        }
        else {
            Write-Output "Name Length >$($response.psobject.Properties.Name.Length)<"
        }
    }
}


Results:

Run Report
Body {"format": "pdf"}

WAITED 30 Seconds for [reporturl]
Value ><
StatusCode ><
Record ><
Mappings ><
> Length <
response psobject Property Name Length is empty
WAITED 30 Seconds for [reporturl]
Value ><
StatusCode ><
Record ><
Mappings ><
> Length <
response psobject Property Name Length is empty
WAITED 30 Seconds for [reporturl]
Value ><
StatusCode ><
Record ><
Mappings ><
> Length <
response psobject Property Name Length is empty
WAITED 30 Seconds for [reporturl]
Value ><
StatusCode ><
Record ><
Mappings ><
> Length <
0

There are 0 answers