VMware Cloud Community
prakee
Contributor
Contributor

Cluster Level Inventory and stats

Hello All,

As i mentioned earlier i am beginner in powercli and i was looking at some scripts about the cluster level stats.. With a  Kind help of LucD i am able to generate a scrip to generate cluster level Memory and CPU stats, how ever i am trying to get the below list of information through powercli script and i have got some ideas from this community and generated the below script which is giving hell a lot of errors. can some one help in getting the below output.....

Note: I have a vcenter version 4.0,5.0, so i am looking for the commandlets which supports both the version.

$report = @()

    $cluster = Get-Cluster

    $esx = $cluster | Get-VMHost

    $vm = $cluster | Get-VM Where-Object {$_.PowerState -eq "Powered On"}

    $vmoff = $cluster | Get-VM Where-Object {$_.PowerState -eq "Powered Off"}

    $ds = Get-Datastore | where {$_.Type -eq "VMFS"}

    $CPUMhzAvg = $_.Group | where {$_.MetricId -eq "cpu.usagemhz.average"} | Measure-Object -Property value -Average 

    $MemoryConsumedavg = $_.Group | where {$_.MetricId -eq "mem.consumed.average"} | Measure-Object -Property value -Average

    New-Object PSObject -Property @{

  $row = "" | Select ClusterName, Numberofhosts,VMon, VMoff, TotalDiskSpace(GB), AvailableDiskSpace(GB), Total Physical Memory (MB), MemoryConsumedavg

  Total CPU (Mhz), CPUMhzAvg

$row.ClusterName = $cluster.Name

$row.Numberofhosts = $esx.count

$row.VMon = $vm.count

$row.vmoff = $vmoff.count

$row.TotalDiskSpaceGB = ($ds | Measure-Object -Property CapacityGB -Sum).Sum

$row.AvailableDiskSpaceGB = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum

$row.Total Physical Memory (MB) = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum

$row.MemoryConsumedavg = $MemoryConsumedavg.Average

$row.Total CPU (Mhz) = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum

$row.CPUMhzAvg = $CPUMhzAvg.Average

$report += $row

  }

$report | Export-Csv "C:\Documents and Settings\Desktop\Cluster123.csv" -NoTypeInformation -UseCulture

0 Kudos
4 Replies
prakee
Contributor
Contributor

Can some one help me in the above script!!!

0 Kudos
kunaludapi
Expert
Expert

$report = @()
$clusters = Get-Cluster
foreach ($cluster in $clusters) {
    $esx = $cluster | Get-VMHost
    $vm = $cluster | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"}
    $vmoff = $cluster | Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"}
    $ds = Get-Datastore | where {$_.Type -eq "VMFS"}
    $CPUMhzAvg = $cluster | Get-Stat -Stat cpu.usagemhz.average | Measure-Object -Property value -Average
    $MemoryConsumedavg = $cluster | Get-Stat -Stat mem.consumed.average | Measure-Object -Property value -Average
    $row = @{}
        $row.'ClusterName' = $cluster.Name
        $row.'Numberofhosts' = $esx.count
        $row.'VMon' = $vm.count
        $row.'vmoff' = $vmoff.count
        $row.'TotalDiskSpaceGB' = ($ds | Measure-Object -Property CapacityGB -Sum).Sum
        $row.'AvailableDiskSpaceGB' = ($ds | Measure-Object -Property FreeSpaceMB -Sum).Sum
        $row.'TotalPhysicalMemory(MB)' = ($esx | Measure-Object -Property MemoryTotalMB -Sum).Sum
        $row.'MemoryConsumedavg' = $MemoryConsumedavg.Average
        $row.'TotalCPU(Mhz)' = ($esx | Measure-Object -InputObject {$_.CpuTotalMhz - $_.CpuUsageMhz} -Sum).Sum
        $row.'CPUMhzAvg' = $CPUMhzAvg.Average
      
      $object = New-Object -TypeName psobject -Property $row
$report += $object
}
$report
--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
prakee
Contributor
Contributor

Thanks  a ton Kunal,

I need latest inventory (VM off, VM on, Total CPU, Memory, Disk) of 30 last days, along with 30 days average CPU & Memory usage value also i need maximum obtained memory and cpu in those 30 days

0 Kudos
prakee
Contributor
Contributor

Helo Kunal.. Can you help me with that...

0 Kudos