VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

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

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

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
19 Replies
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

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

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

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

Thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Even output are jumbled up.Smiley Sad

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

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

thanks

vmk

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

After running the alternative script, please find the output

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:22 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:22 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:22 char:5

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

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

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

    + FullyQualifiedErrorId : MethodNotFound

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I made a small change to the latest version of the script.
Can you give that one a try?


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

Yes, it's working now. No error this time.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect it was due to the fact that you had a cluster with 1 VM that has reservations.
That way the array $report became a scalar instead of an array, and then the += to add the Total wasn't working anymore.

By changing the = on the Select to a +=, we made sure that $report stayed an array.


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

vmk2014
Expert
Expert
Jump to solution

Thank you LucD !!

Reply
0 Kudos