Adding Your Own Plugin to vCheck6

The vCheck PowerCLI script from Alan Renouf is one of the most popular scripts for managing vSphere with PowerCLI. Its an amazing piece of work and I think has in its own small way helped the success of PowerCLI itself, by showing the kind of information it is possible to retrieve from vSphere and present in a great format. The number of people I talk to who use it and the large scale organisations that you would think spend thousands of pounds on expensive monitoring tools that have it as part of the daily monitoring checks never ceases to surprise me.

Alan has just released version 6 of vCheck and has taken the time to look at it from scratch, take in feedback from the 400+ comments he has received back about it and implement it in such a fashion that it is possible for you to extend it simply yourself. The script has been split out into some general components and a seperate Plugins folder.

Each of the individual checks that vCheck makes against your vSphere environment is stored in this Plugins folder. If you wish to make your own check to add to vCheck then all you need to is add a new *.ps1 file containing some required header information and the code to run the check. This is brilliant and really saves any hassle from the previous versions where you had to put your own code in to the right place in the script to make it work. Below I have added number 46 Cluster Capacity.

This script contains the following required code. Here you can supply details about the script, various parts of which will be displayed during the execution of the script and in the resulting report, for instance you can place a link to a website containing more info about the check - in this case I have placed a link to my blog post about how the cluster capacity check works.

$Title = "Basic Cluster Capacity" $Header =  "Basic Cluster Capacity" $Comments = "Retrieve Cluster Capacity Information. For details see" $Display = "Table" $Author = "Jonathan Medd" $Version = 1.0

The full code for this particular example is below:

$Title = "Basic Cluster Capacity" $Header =  "Basic Cluster Capacity" $Comments = "Retrieve Cluster Capacity Information. For details see" $Display = "Table" $Author = "Jonathan Medd" $Version = 1.0

\# Start of Settings # End of Settings

function Get-ClusterCapacityCheck { <# .SYNOPSIS Retrieves basic capacity info for VMware clusters

.DESCRIPTION Retrieves basic capacity info for VMware clusters

.PARAMETER&nbsp; ClusterName Name of the computer to test the services for

.EXAMPLE PS C:\\> Get-ClusterCapacityCheck -ClusterName Cluster01

.EXAMPLE PS C:\\> Get-Cluster | Get-ClusterCapacityCheck

.NOTES Author: Jonathan Medd Date: 18/01/2012 #>

\[CmdletBinding()\] param( \[Parameter(Position=0,Mandatory=$true,HelpMessage="Name of the cluster to test", ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)\] \[System.String\] $ClusterName )

begin { $Finish = (Get-Date -Hour 0 -Minute 0 -Second 0) $Start = $Finish.AddDays(-1).AddSeconds(1)

New-VIProperty -Name FreeSpaceGB -ObjectType Datastore -Value { param($ds) \[Math\]::Round($ds.FreeSpaceMb/1KB,0) } -Force


process {

$Cluster = Get-Cluster $ClusterName

$ClusterCPUCores = $Cluster.ExtensionData.Summary.NumCpuCores $ClusterEffectiveMemoryGB = \[math\]::round(($Cluster.ExtensionData.Summary.EffectiveMemory / 1KB),0)

$ClusterVMs = $Cluster | Get-VM

$ClusterAllocatedvCPUs = ($ClusterVMs | Measure-Object -Property NumCPu -Sum).Sum $ClusterAllocatedMemoryGB = \[math\]::round(($ClusterVMs | Measure-Object -Property MemoryMB -Sum).Sum / 1KB)

$ClustervCPUpCPURatio = \[math\]::round($ClusterAllocatedvCPUs / $ClusterCPUCores,2) $ClusterActiveMemoryPercentage = \[math\]::round(($Cluster | Get-Stat -Stat mem.usage.average -Start $Start -Finish $Finish | Measure-Object -Property Value -Average).Average,0)

$VMHost = $Cluster | Get-VMHost | Select-Object -Last 1 $ClusterFreeDiskspaceGB = ($VMHost | Get-Datastore | Where-Object {$\_.Extensiondata.Summary.MultipleHostAccess -eq $True} | Measure-Object -Property FreeSpaceGB -Sum).Sum

New-Object -TypeName PSObject -Property @{ Cluster = $Cluster.Name ClusterCPUCores = $ClusterCPUCores ClusterAllocatedvCPUs = $ClusterAllocatedvCPUs ClustervCPUpCPURatio = $ClustervCPUpCPURatio ClusterEffectiveMemoryGB = $ClusterEffectiveMemoryGB ClusterAllocatedMemoryGB = $ClusterAllocatedMemoryGB ClusterActiveMemoryPercentage = $ClusterActiveMemoryPercentage ClusterFreeDiskspaceGB = $ClusterFreeDiskspaceGB } } }

$Clusters | Get-ClusterCapacityCheck | Select-Object Cluster,ClusterCPUCores,ClusterAllocatedvCPUs,ClustervCPUpCPURatio,



Now when you execute vCheck6 you will see your own plugin executed at the end of the script run.

And if your plugin generates some data for the vCenter it has been run against, then it will appear in the report.

The possibilites for this are endless and don’t necessarily need to only extend to vSphere. Think of it as a reporting framework into which you could plugin information from any system that you can access via PowerShell, say Windows Server, Exchange, SQL, Citrix, your SAN etc. Brilliant stuff!