VMware Cloud Community
vespavbb
Enthusiast
Enthusiast
Jump to solution

Count VM´s by OS and Measure Memory, cpu

Hi,

I try to create a report for counting VM´s memery and cpu useby certain Os and Sort on Cluster level. I want to improve the output by meassure the mem and cpu count on clusterlevel for a certian OS Type

Someting like this:

Name

cluster1

cluster2

cluster3

cluster4

cluster5

cluster6

vcpu

12

34

81

89

0

94

ram

0

8

19

19

0

178

UsedGB12341455612

$mycluster = Get-Cluster

$myCol = @()

$error.Clear()

foreach ($vmlist in $mycluster)

{

foreach ($vm1 in $vmlist)

{

  

   $vminfo =  $vm1 | Select name,

   

   

    @{n="2008";e={($_ | get-vm | Where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*2008'}).count}},

     @{n="MemoryGB";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "memoryGB" }

     @{n="vcpu";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "Num CPUs" }

     @{n="UsedGB";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "UsedGB" }

   

    #@{n="memory";e={($_ | get-vm | Where {$_.powerstate -eq 'PoweredOn' -and  $_.Guest.OSFullName -match 'Windows.*2008' } | Measure-Object -sum "memoryGB"}},

    $myCol += $VMInfo

   

 

}

}

$myCol

VCP4,VCP5,VCP6,VCP7,VCP8
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Producing the data could be done like this.

Get-Cluster -PipelineVariable cluster |

ForEach-Object -Process {

    $vms = Get-VM -Location $cluster |

        where{$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008'}

    New-Object -TypeName PSObject -Property ([ordered]@{

        Name = $cluster.Name

        2008 = $vms.Count

        MemoryGB = ($vms.MemoryGB | Measure-Object -Sum ).Sum

        vCPU = ($vms.NumCpu | Measure-Object -Sum ).Sum

        UsedGB = [math]::Round(($vms.UsedSpaceGB | Measure-Object -Sum ).Sum,1)

    })

}

Transposing the result is something that might be a bit harder, if not impossible with the current property names and values, to accomplish.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

And besides the obvious error in the foreach loops, is there a question in here?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vespavbb
Enthusiast
Enthusiast
Jump to solution

question is, how i could do a report on Clusterlevel to measure the ram,cpu and diskspace usage of all windows 2008 servers...in sum.

the script is buggy because I was struggle in the middle,

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Producing the data could be done like this.

Get-Cluster -PipelineVariable cluster |

ForEach-Object -Process {

    $vms = Get-VM -Location $cluster |

        where{$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008'}

    New-Object -TypeName PSObject -Property ([ordered]@{

        Name = $cluster.Name

        2008 = $vms.Count

        MemoryGB = ($vms.MemoryGB | Measure-Object -Sum ).Sum

        vCPU = ($vms.NumCpu | Measure-Object -Sum ).Sum

        UsedGB = [math]::Round(($vms.UsedSpaceGB | Measure-Object -Sum ).Sum,1)

    })

}

Transposing the result is something that might be a bit harder, if not impossible with the current property names and values, to accomplish.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vespavbb
Enthusiast
Enthusiast
Jump to solution

awesome, thanks LUC

VCP4,VCP5,VCP6,VCP7,VCP8
Reply
0 Kudos