Check numer of running and stopped Vm’s in each resource group

Here is another powershell PowerCLI script that will give you the number of running and stopped Vm’s grouped by Cluster and Resource group.

# Add in the VI Toolkit goodness
if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null ){Add-PSsnapin VMware.VimAutomation.Core}

$VCs =@(“srv-vc-0001″,”srv-vc-0002”)
$date=Get-Date -format “yyMMd”
$file = “c:\temp\VmwareStats$date.csv”

function GetVmwareStats
{
$report = @()
foreach ($VC in $VCs)
{
Connect-VIServer $VC | Out-Null

foreach ($Cluster in Get-Cluster)
{
#write-host $Cluster
$allcount = @()
foreach ($resourcepool in (Get-ResourcePool -Location $Cluster | Where {$_.Name -ne “Resources“ }))
{
$count = “” | Select Cluster,Hostname,ResourcePool, RunningVms, StoppedVms
$count.HostName = $vmHost.name
$count.Cluster = $Cluster.Name
$RunningsVms = Get-VM -Location $Cluster,$ResourcePool -NoRecursion | Where {$_.PowerState -eq “PoweredOn”}
$StoppedVms =Get-VM -Location $Cluster,$ResourcePool -NoRecursion | Where {$_.PowerState -eq “PoweredOff”}
$count.RunningVMs = $RunningsVms.Count
$count.StoppedVms = $StoppedVms.Count
$count.ResourcePool = $ResourcePool.Name
$allcount += $count
}
$allcount | Select Cluster, ResourcePool, RunningVms, StoppedVms
}
$report += $allcount
}

}

GetVmwareStats |export-Csv $file -notypeinformation -Delimiter “;”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s