Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 240675

Script for showing VM statistics does not show the correct Cluster name.

$
0
0

I tried to add a column to show which cluster the VM is in, but appearently I did it wrong.  The column does list a cluster, but it is the wrong one, and it is the same for all VMs.

 

 

#####################################
# VMware Virtual Machine statistics #
#####################################

function VM-statavg ($vmImpl, $StatStart, $StatFinish, $statId) {
$stats = $vmImpl | get-stat -Stat $statId -intervalmin 120 -Maxsamples 360 `
           -Start $StatStart -Finish $StatFinish
$statAvg = "{0,9:#.00}" -f ($stats | Measure-Object value -average).average
$statAvg
}
# Report for previous day
$DaysBack = 30  # Number of days to go 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 previous week
$DaysBack = 7 # Number of days to go 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.HostName = $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 -Append $filelocation


Viewing all articles
Browse latest Browse all 240675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>