The following example executes a report, saves the output as a CSV file, PDF file, or Microsoft Word document and opens the file in the default document viewer.

  • Connect to the reporting web service.

  • Specify the file format as either "DOCX" or "PDF".

  • Specify the unique identifier of the report to execute in GUID format.

  • Optionally specify the customer or container against which to execute the report, by default this is the root container with identifier 1000.

  • Optionally 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


# Set the file format to CSV/DOCX/PDF.

$fileformat = "DOCX";

$reportIdentifier = [Guid]"5413a609-80da-490b-ad76-104aa8d4021f";


# Generate the execution settinsg.

$executionSettings = $reporting.DO_CreateReportExecutionSettings($reportIdentifier);


# Optionally set the customer or container.

$executionSettings.ContainerId = 1000;


# Optionally set sort order and sort column.

$executionSettings.SortOrder = "Ascending";

$executionSettings.SortColumn = 1; 


# Execute the report.

$documentPackage = $reporting.DO_ExecuteReport($executionSettings, $fileformat);


# Save and open the file.

$filename = "$($env:TEMP)\$($documentPackage.Filename)"

[IO.File]::WriteAllBytes($filename, $documentPackage.FileData);

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

$parameterValues = $executionSettings.ParameterValues;

$reporting.SET_ReportParameterValue([ref]$parameterValues, "ServerName", "DEMO-SRV01");

$reporting.SET_ReportParameterValue([ref]$parameterValues, "Age", 31);

$executionSettings.ParameterValues = $parameterValues