4 Replies Latest reply on Jan 21, 2020 8:15 AM by vespavbb

    Count VM´s by OS and Measure Memory, cpu

    vespavbb Novice

      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

        • 1. Re: Count VM´s by OS and Measure Memory, cpu
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

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

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Count VM´s by OS and Measure Memory, cpu
            vespavbb Novice

            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,

            • 3. Re: Count VM´s by OS and Measure Memory, cpu
              LucD Guru
              Community WarriorsvExpertUser Moderators

              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: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Count VM´s by OS and Measure Memory, cpu
                vespavbb Novice

                awesome, thanks LUC