Script of statistics VM does not show the good name of the Cluster.

I tried to add a column to display the cluster virtual machine which is, but appearently I hurt him.  The column lists a cluster, but it's evil, and it's the same for all virtual machines.

#####################################
# Statistics virtual machine VMware #.
#####################################

function {VM-statavg ($StatStart, $StatFinish, $vmImpl, $statId)
$stats = $vmImpl | Get-stat - Stat $statId - intervalmin 120 - Maxsamples 360'
-Launch $StatStart - finishing $StatFinish
$statAvg = "{0, 9:.00 #} ' f ($stats |) Measure - Object value - average) subject
$statAvg
}
# Eve report
$DaysBack = 30 # number of days to return back
$DaysPeriod = 30 # number of days in the interval
$DayStart = (get-Date). Date.AddDays(-$DaysBack)
$DayFinish = (get-Date). Date.AddDays (-$DaysBack + $DaysPeriod).addminutes(-1)
# Report for the previous week
$DaysBack = 7 # number of days to return back
$DaysPeriod = 7 # number of days in the interval
$WeekStart = (get-Date). Date.AddDays(-$DaysBack)
$WeekFinish = (get-Date). Date.AddDays (-$DaysBack + $DaysPeriod).addminutes(-1)
$report = @)
Get - vm | Sort name | % {
$vm = get-view $_.ID
$vms = "" | Select-Object VMName Hostname, Cluster, MonthAvgCpuUsage, WeekAvgCpuUsage, VMState, TotalCPU, TotalMemory, MonthAvgMemUsage, WeekAvgMemUsage, TotalNics, ToolsStatus, ToolsVersion
$vms. VMName = $vm. Name
$vms. Host name = $vm.guest.hostname
$vms. Cluster = $Cluster.Name
$vms. MonthAvgCpuUsage = VM-statavg $_ $DayStart $DayFinish "cpu.usage.average".
$vms. WeekAvgCpuUsage = VM-statavg $_ $WeekStart $WeekFinish "cpu.usage.average".
$vms. VMState = $vm.summary.runtime.powerState
$vms. TotalCPU = $vm.summary.config.numcpu
$vms. TotalMemory = $vm.summary.config.memorysizemb
$vms. MonthAvgMemUsage = VM-statavg $_ $DayStart $DayFinish "mem.usage.average".
$vms. WeekAvgMemUsage = VM-statavg $_ $WeekStart $WeekFinish "mem.usage.average".
$vms. TotalNics = $vm.summary.config.numEthernetCards
$vms. ToolsStatus = $vm.guest.toolsstatus
$vms. ToolsVersion = $vm.config.tools.toolsversion
$Report += $vms
}

$Report | ConvertTo-Html-title "VMware Virtual Machine statistics" - body "< H2 > VMware Virtual Machine statistics.» "< / H2 > ' | Out-file - add $filelocation

Looks like you forgot to get the cluster.

The first lines of the loop must be something like this

...

Get - vm | Sort name | % {
$vm = get-view $_.ID

$cluster = get-Cluster - VM $_

....

Tags: VMware

Similar Questions

Maybe you are looking for

  • Using scan on HP Photosmart 2575

    Hello I have the problem I have HP Photosmart 2575xi, the cartridges were empty, I have removed them and put in the trash. now I need to scan a document, but can not turn on the printer, it asks to insert the cartridges. is it possible to scan USING

  • How to hide the sub Pop out VI executing main VI

    Hi all: I have a problem running the main VI 'ProConsume for HP8903B.vi', two under VI ejects automatically, the Ref HP8903B read values.vi & the Ref HP8903B Setup before read.vi is really annoying, whenever I click on "single button" on the main faç

  • Call dll ActiveX in Labview

    Hello I'm a new starter in c# .net.  I have a control dll ActiveX (control of vision of NOR -> CWIMAQ). I need to call dll functions in Labview. I searched for articles on this subject. Everyone talks about single thread and register the dll.  I have

  • ERRORS ON SERVER?

    Time on our server keeps slowing by about 5 minutes after a week or two to redefine every time.  What can I do?  It is up-to-date and running on Windows Server 2008 R2.

  • OfficeJet Pro 6800

    I have an iMac, OS 10.6.8. I bought an Officejet Pro 6800 in August 2013, new in box. To install wireless to the router. Worked fine until that HP pushed a software update for the printer via Apple Software Update week from 13 to 13 Oct. Since that t