You may come across situations where it makes sense to export vROps reports (continuously) using PowerShell instead of using the build in solutions.
There is a very good blog article about how to leverage PowerCLI to extract vROps reports, which you can find here. A huge thanks to @_ryanjan_ for sharing this information and to create and share the excellent helper-module.
However, when trying to do export reports using PowerShell, I faced some problems:
- The report id changes, so we need a variable for that.
- The exported report must change name each time it is being exported, or any following export will try to use the same name of the report that is already there. This is especially needed when the exported report is
The solution for the 2 problems above is simple:
- Create a variable for the report ID.
- Add a more granular timestamp in the name of the reports.
The starting point: Create a variable for the Report ID.
We start this article at the PowerShell script at the following line in Ryan’s script:
New-OMReport -Resource $Resource -ReportDefinition $ReportDefinition -TraversalSpec $TraversalSpec
Create the report variable. I will call my variable $NOM. If you do not do this and use the report ID directly, you will see the following error on the next executions of the script:
$NOM = New-OMReport -Resource $Resource -ReportDefinition $ReportDefinition -TraversalSpec $TraversalSpec
Next you need to find the extension for the ‘id’ to add to $NOM. When you use ISE, you can see all extensions for the $NOM variable you have created, such as here:
So to extract the ID number of $NOM, you just have to append ‘id’to $NOM
$NOM.Id
The ‘$NOMid’ is the string value you need. So create a variable for $NOM.Id. I call my variable $Id.
$Id = $NOM.Id
Delay the export
Next you want to export the report you have generated above. However, some reports take time to be generate. There is no point in exporting a blank report, so pause the script until the report has been generated fully. I will give vROps 180 seconds to generate it, before exporting it.
Start-Sleep -Seconds 180
Add a timestamp in the name of the reports
Next export the report using the $id variable and add the timestamp in the name of the exported report. The format in my timestamp is in the following order: hours, minutes, day, month and year.
$Report = Get-OMReport -Id $Id $path = "C:\vROps-Reports\Reports\report" + (get-date -format "-hh-mm-dd-MM-yyyy") + ".pdf" Receive-OMReport -Report $Report -PDF -Path $path
Continuous export
To export them continuously, you can create an automated task to run the PowerShell script at the intervals you want the report.
Kim
Thanks for the tutorial. I’m getting this error in Receive-OMReport
Receive-OMReport: Exception calling “DownloadReport” with “2” argument(s): “Data at the root level is invalid. Line 1, position 1.”
Did you ever figure out the solution?
Getting the same error, error suggests the data is not XML (which its not).. Tried both MemoryStream and FileStream options with the exact same error