Updated for vRops token based auth here
So I needed to automatically run an oversized VM report on a few vRops environments and combine them into one report.
This isn’t my full script as I take the csv and combine is with other data from other metadata, database..etc… but hopefully the following example script / function might help you… It executes the report via the suite-api, waits for it to finish and downloads the csv to a local folder.
First things first… update line 15 in the example script below with your own vRops server IP or FQDN.
$vRopsAddress = 'vc.vman.local'
So that I don’t keep being prompted for credentials I save the service account user and password with the powershell Get-Credential command.
$cred = Get-Credential $cred | Export-Clixml -Path "d:\vRops\Config\vc.xml"
Once you have generated the XML update line 16 to reflect your *.XML file
$vRopsCreds = Import-Clixml -Path "$ScriptPath\config\VC.xml"
Now that we got that out of the way… we need to obtain the ResourceID for the object / level we wish to run the report for, in my case i want to run it for the whole VC so the easiest way to find the ResourceID for the VC is to use the vRops GUI, search for the VC and get the ResourceID from the URL.
Go to line 17 in the code below and update it to match your ResourceID
$vCenter = '7d3a8453-6559-4d4c-9005-3f8655e4394f'
Now we need to do something similar for the Report that the script will run… So in the vRops GUI, navigate to Content, Reports, Click on Generated Reports
Once you click on Generated Reports you will notice that the URL now has an ID for the Report
Go to line 18 in the code below and update it to match the Report ID
$Report = '1f69952f-7ff4-4d2c-9446-81a811de19b0'
if you found this post useful please consider checking out one of the sponsored links to keep the site running…
full script below…
<# The following command must be run once to generate the Credential file to connect to each environment. Run once for per virtual center $cred = Get-Credential $cred | Export-Clixml -Path "c:\vRops\Config\vc.xml" #> #vars $ScriptPath = (Get-Item -Path ".\" -Verbose).FullName $Output = $ScriptPath +'\Reports\' $vRopsAddress = 'vc.vman.local' $vRopsCreds = Import-Clixml -Path "$ScriptPath\config\VC.xml" $vCenter = '7d3a8453-6559-4d4c-9005-3f8655e4394f' $Report = '1f66552f-7bb4-4d2c-9661-81a811de19b0' ## Function Function GetReport([String]$vRopsAddress, [String]$vCenter, [String]$Report, [String]$Env, $vRopsCreds, $Path){ Write-host 'Running Report for' $Env #Take all certs. add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy #RUN Report $ContentType = "application/xml;charset=utf-8" $header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $header.Add("Accept", 'application/xml') $RunReporturl = 'https://'+$vRopsAddress+'/suite-api/api/reports' $Body = @" <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ops:report xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ops="http://webservice.vmware.com/vRealizeOpsMgr/1.0/"> <ops:resourceId>$vCenter</ops:resourceId> <ops:reportDefinitionId>$Report</ops:reportDefinitionId> <ops:traversalSpec adapterInstanceAssociation="false"> <ops:name>vSphere Hosts and Clusters</ops:name> <ops:rootAdapterKindKey>VMWARE</ops:rootAdapterKindKey> <ops:rootResourceKindKey>vSphere World</ops:rootResourceKindKey> </ops:traversalSpec> </ops:report> "@ [xml]$Data = Invoke-RestMethod -Method POST -uri $RunReporturl -Credential $vRopsCreds -ContentType $ContentType -Headers $header -Body $body $ReportLink = $Data.report.links.link.href $ReportLinkurl = 'https://' + $vRopsAddress + $ReportLink #Check if report is run to download [xml]$ReportStatus = Invoke-RestMethod -Method GET -uri $ReportLinkurl -Credential $vRopsCreds -ContentType $ContentType -Headers $header While ($ReportStatus.report.status -ne "COMPLETED") { [xml]$ReportStatus = Invoke-RestMethod -Method GET -uri $ReportLinkurl -Credential $vRopsCreds -ContentType $ContentType -Headers $header Write-host 'Waiting for' $Env 'report to finish running, current status: ' $ReportStatus.report.status Sleep 3 } # End of block statement $ReportDownload = $ReportLinkurl + '/download?format=CSV' $ReportOutputfile = $Path + '\collections\' + $Env + '_OversizedVMReport.csv' Invoke-RestMethod -Method GET -uri $ReportDownload -Credential $vRopsCreds -ContentType $ContentType -Headers $header -OutFile $ReportOutputfile Write-host 'Report for' $Env 'finished' return $ReportOutputfile } $Report = GetReport $vRopsAddress $vCenter $Report 'VC' $vRopsCreds $ScriptPath
I have tried this scrip on vROps 6.6 and i am facing problem in downloading report. URI for report to be downloaded is giving “HTTP 404” error. The “$ReportLinkurl” variable is not getting updated with proper report path.
Hello, Sorry i didn’t get to you until now…
Are you sure you have the correct Report ID variable $Report = ‘XXXXXX’ specified in the script for your report?
Cheers
vMan
Loved this script! I changed line 65 to
$Reportlink = $Data.report.links.link.href[0] as there were multiple links. I could of course have pick it out by name as a more permenent fix.
thanks for the comment, I will have to check that out and maybe Handle it differently
Very helpful. Thank you very much.
Thanks for the script. It works great for 7.5 but for vRops 8.0.1 there must be some changes, because this part:
$Body = @”
$vCenter
$Report
vSphere Hosts and Clusters
VMWARE
vSphere World
“@
creates report for vCenter Python Actions Adapter instead of vSphere World. Thanks.
Just to be sure, I have version 8.0.1.15331180
Build 15331180
I think I solved it. There was incorrect vCenter id. Thanks anyway!
Great! I was planning on looking at it tonight but sounds like no need now 🙂 I am glad you find the script is useful.
vMan
Hi vMan, any chance updating the script to support token-based authentication? Basic authentication method is obsolete as of now and has to be enabled with a workaround (which could not work in the future). Thanks for the answer.
Yeah sure, I will see what I can do this week, I have a function for token based auth, just not ported it over to all my scripts.
Here is the new version of the script: https://vman.ch/vrops-suite-api-createreport-downloadreport-update/