Execute a Report to PDF
The following example executes a report, saves the output as a PDF document and opens the file in the default PDF document viewer.
- Connect to the reporting web service.
- Specify the unique identifier of the report to execute in GUID format.
- Specify the customer or container against which to execute the report, by default this is the root container with identifier 1000.
- Set the sort order to "Ascending" or "Descending", and the sort column as a numeric value starting at 1. This has no effect if the report does not support sorting.
- Optionally set the report parameter values.
- The user must have permissions to execute this report.
Code Sample
# Executes the report and saves the output as a PDF file in the user's temp directory.
$filename = "$env:TEMP\ReportOutput.pdf"
$reportIdentifier = [Guid]"5413a609-80da-490b-ad76-104aa8d4021f";
$parameterValues = $reporting.GET_DefaultReportParameterValues($reportIdentifier);
$output = $reporting.DO_ExecuteReportPdf($reportIdentifier, $parameterValues, 1000, "Ascending", 1);
[IO.File]::WriteAllBytes($filename, $output);
[System.Diagnostics.Process]::Start($filename);
To configure the parameters for the report use the SET_ReportParameterValue method. For example to set the "ServerName" parameter to "DEMO-SRV01" and the "Age" parameter to 31 use the following commands.
$reporting.SET_ReportParameterValue([ref]$parameterValues, "ServerName", "DEMO-SRV01");
$reporting.SET_ReportParameterValue([ref]$parameterValues, "Age", 31);