PowerCLI for vROps – Getting started

PowerCLIPowerCLI 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

pwcli_001

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

pwcli_002

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)

pwcli_003

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.

pwcli_004

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 -neGreen” 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

pwcli_005pwcli_006

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.

pwcli_011.PNG

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"

pwcli_008pwcli_009

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.

pwcli_010

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

8 thoughts on “PowerCLI for vROps – Getting started

Add yours

  1. Very well writteVery well written Sid. Write more blogs like these. Helpful.n Sid. Write more blogs like these. Helpful.

    Like

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

    Like

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

      Like

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

      Like

Leave a comment

Blog at WordPress.com.

Up ↑