PowerCLI or PowerShell scripting is a great way to automate day-to-day tasks as well as performing complex operations. There are large number of customers who extensively use PowerCLI within their vSphere environment to fetch various infrastructure related details. One can write a simple script to get VM, Datastore, Cluster and many more results within no time. However not many of the customer use PowerCLI for their vROps environment. Although all the information which is collected using API call is available on dashboard as well but sometimes running one liner command to get desired result is more convenient than logging into vROps and then looking for the right dashboard.
In order to get required modules we need PowerCLI 6.2.x (or later) version which contains vROps module (VMware.VimAutomation.vROps). In my lab I have PowerCLI 6.3 R1 installed. You can use get-powercliversion command to get version related information
To check whether required modules are installed on your system you can run command get-Module and check if VMware.VimAutomation.* & VMware.VimAutomation.vROps modules are available. Alternatively browse to this location (C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules) and confirm if necessary modules are available
While using PowerShell to connect to vCenter server Connect-VIServer command is used similarly to connect to vROps server Connect-OMServer is used, where OMServer refers to Operation Manager Server (rest of the syntax remains the same)
Now let’s start with something very basic to get vm related information. To get virtual machine information use Get-VM | Get-OMResource command. Here input of typical Get-VM is filtered based upon the vm related information available from vROps. In below example we can see that by using this argument more granular results are seen with Health status and resource kind of virtual machines.
Now the above command can be made even more granular where we filter the output based upon the health badge. In below example we are listing out all virtual machine whose health isn’t green (notice -ne “Green” argument). It gives one extra mile while working on performance related issues to identify problematic vms. Same approach can be applied on Datastore, ESXi host or Cluster as well to get health related information.
Imagination is the key which information we want to publish and in which format
Similar way we can also capture alerts using simple cmdlet, in below example I’m capturing all Active alerts from vRops whose Status isn’t Green and then formatting it into readable format.
Let’s consider an example where I want to collect avg CPU performance report for a particular virtual machine of last 24 hours (or 1 day) and store it in .csv format. I can do this by simply running below 2 line command and the result will look like shown in screenshot.
$D = Get-OMStat -Resource 'psvcenter' -Key 'cpu|capacity_usagepct_average'-From ( [DateTime]::Now).AddDays(-1) $D | Export-Csv -Path "C:\Users\sidharths\Desktop\test1.csv"
Similarly if I want to collect health badge for a particular virtual machine (psvcenter in my case) I can run a single line command and get the result right on the powershell screen.
Now the real question – What is the benefit of using PowerShell cmdlet for vROps whereas I can get exact same information from its dashboard..?
Honest Answer is – PowerShell/PowerCLI gives the ability to fetch results right from the API level which saves time and you can drill down the exact piece of information you are looking for – which is tribal way of troubleshooting . That’s why command line tools are always popular among admins who spend most of their time working on break-fixes.
With this I end this blog… I hope it helps… till then Happy Reading.. 🙂
Very well writteVery well written Sid. Write more blogs like these. Helpful.n Sid. Write more blogs like these. Helpful.
LikeLike
Thank you so much fo your feedback, it means a lot 🙂
LikeLike
Awesome blogs.. 🙂
LikeLike
Thanks Sridhar
LikeLike
Is there a way to get this ‘key’ out of an alert via CLI? Say I got an alert with get-omalert, i can get resource, badges, etc. But can i find what symptom has been triggered? And having the symptom (and the key) i can collect omstat to add some useful info into the alert data (without looking into VROPS console).
Thanks
LikeLike
Hi Alex, please check below list which has number of get (alert) modules which can be used to collect desired information
Alerts
– Get-OMAlerts
– Get-OMAlertDefinitions
– Get-OMAlertType
– Get-OMAlertSubType
– Set-OMAlert
– Get-Recommendations
I hope this is what you were looking for.
LikeLike
Is there a way that I can get a EPOPs agent version
LikeLike
Hi Gautham, Usually once you install any EPops agent on a vm and configure it to report to vROps. Under Administration tab of vROps you can see the reporting agent and there is version information as well.
LikeLike