1 2 Previous Next 19 Replies Latest reply on Dec 24, 2018 8:04 AM by vmk2014

    Can we pull the lists of VM having Memory reservation and CPU ?

    vmk2014 Expert

      Hi Everyone,

       

      Can we pull the lists of VM having Memory reservation and CPU ? Also, how much Memory in GB having reservations and vCPU.

       

      thanks

      vmk

        • 1. Re: Can we pull the lists of VM having Memory reservation and CPU ?
          Srinivasu13 Enthusiast

          A quick small post to list the memory limits on the VM and set it back to unlimited using a PowerCLI

           

           

          To list the VM’s which have memory limit configured

           

              Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne ‘-1’}  | Select VM,MemLimitMB

           

           

          And to set it to unlimited

           

              Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne ‘-1’}  | Set-VMResourceConfiguration -MemLimitMB $null

           

           

           

          For CPU the attributes to be changed to CpuLimitMhz

          • 2. Re: Can we pull the lists of VM having Memory reservation and CPU ?
            vmk2014 Expert

            Thank you. Since we have a large environment so trying to pull the lists for around 15 VM's which is having reservations.

            • 3. Re: Can we pull the lists of VM having Memory reservation and CPU ?
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Try like this

               

              Get-VM -PipelineVariable vm |

              Get-VMResourceConfiguration |

              where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |

              select @{N='VM';E={$vm.Name}},

                  CpuReservationMhz,MemReservationGB

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                vmk2014 Expert

                LucD,

                 

                Can we pull reservation at Cluster and Total memory  reserved ( Sum)

                 

                Thanks

                vmk

                • 5. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  Try like this

                   

                  Get-Cluster -PipelineVariable cluster |

                  ForEach-Object -Process {

                      $report = Get-VM -Location $cluster -PipelineVariable vm |

                      Get-VMResourceConfiguration |

                      where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |

                      select @{N='Cluster';E={$cluster.Name}},

                          @{N='VM';E={$vm.Name}},

                          CpuReservationMhz,MemReservationGB

                     

                      $report += "" | Select @{N='Cluster';E={$cluster.Name}},

                          @{N='VM';E={'Total'}},

                          @{N='CpuReservationMhz';E={($report | Measure-Object -Property CpuReservationMhz -Sum).Sum}},

                          @{N='MemReservationGB';E={($report | Measure-Object -Property MemReservationGB -Sum).Sum}}

                      $report

                  }

                   

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                    vmk2014 Expert

                    LucD,

                     

                    Sorry, to say some goof up happened, it's not picking the right cluster name. For every VM's showing in almost all the cluster though the VM is mapped to single cluster.

                     

                    Thanks

                    vmk

                    • 7. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                      LucD Guru
                      vExpertCommunity WarriorsUser Moderators

                      Yes, you are right, I forgot the Location parameter on the Get-VM cmdlet.
                      I updated the code above.

                      Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                      • 8. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                        vmk2014 Expert

                        Ok LucD,

                         

                        I ran once again the scripts but it throws an error

                         

                        PS C:\temp> .\Memory_reservation.ps1

                        Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.

                        At C:\temp\Memory_reservation.ps1:23 char:5

                        +     $report += "" | Select @{N='Cluster';E={$cluster.Name}},

                        +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                            + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException

                            + FullyQualifiedErrorId : MethodNotFound

                         

                         

                        Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.

                        At C:\temp\Memory_reservation.ps1:23 char:5

                        +     $report += "" | Select @{N='Cluster';E={$cluster.Name}},

                        +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                            + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException

                            + FullyQualifiedErrorId : MethodNotFound

                         

                         

                        Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.

                        At C:\temp\Memory_reservation.ps1:23 char:5

                        +     $report += "" | Select @{N='Cluster';E={$cluster.Name}},

                        +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                            + CategoryInfo          : InvalidOperation: (op_Addition:String) [], RuntimeException

                            + FullyQualifiedErrorId : MethodNotFound

                        thanks

                        vmk

                        • 9. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                          vmk2014 Expert

                          Even output are jumbled up.

                          • 10. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            Which PowerShell version are you using?

                            Do a $PSVersionTable

                             

                            As an alternative, try like this

                             

                            Get-Cluster -PipelineVariable cluster |

                            ForEach-Object -Process {

                                $report = @()

                                $report += Get-VM -Location $cluster -PipelineVariable vm |

                                Get-VMResourceConfiguration |

                                where{$_.CpuReservationMhz -ne 0 -or $_.MemReservationMb -ne 0} |

                                select @{N='Cluster';E={$cluster.Name}},

                                    @{N='VM';E={$vm.Name}},

                                    CpuReservationMhz,MemReservationGB

                                $report += "" | Select @{N='Cluster';E={$cluster.Name}},

                                    @{N='VM';E={'Total'}},

                                    @{N='CpuReservationMhz';E={($report | Measure-Object -Property CpuReservationMhz -Sum).Sum}},

                                    @{N='MemReservationGB';E={($report | Measure-Object -Property MemReservationGB -Sum).Sum}}

                                $report

                            }

                             

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                              vmk2014 Expert

                              LucD,

                               

                              I'm using power Cli version 11. Will check belwo script and update you.

                               

                              thanks

                              vmk

                              • 12. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                                LucD Guru
                                User ModeratorsvExpertCommunity Warriors

                                I meant the PowerShell version (check by displaying what is in $PSVersionTable).

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 13. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                                  vmk2014 Expert

                                  PS C:\> $PSVersionTable

                                   

                                   

                                  Name                           Value

                                  ----                           -----

                                  PSVersion                      5.1.14409.1018

                                  PSEdition                      Desktop

                                  PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

                                  BuildVersion                   10.0.14409.1018

                                  CLRVersion                     4.0.30319.42000

                                  WSManStackVersion              3.0

                                  PSRemotingProtocolVersion      2.3

                                  SerializationVersion           1.1.0.1

                                  • 14. Re: Can we pull the lists of VM having Memory reservation and CPU ?
                                    vmk2014 Expert

                                    PS C:\> $PSVersionTable

                                     

                                     

                                    Name                           Value

                                    ----                           -----

                                    PSVersion                      5.1.14409.1018

                                    PSEdition                      Desktop

                                    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

                                    BuildVersion                   10.0.14409.1018

                                    CLRVersion                     4.0.30319.42000

                                    WSManStackVersion              3.0

                                    PSRemotingProtocolVersion      2.3

                                    SerializationVersion           1.1.0.1

                                    1 2 Previous Next