VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get-VMhost with less memory used

Hi,

I am trying to get the VMhost name which has less memory used

How can I select the host which has low memory usage from the below command, Please help,

Get-Cluster MyClus | Get-VMHost | Select Name, @{N='Memory Used GB';E={[math]::Round($_.MemoryUsageGB,2)}} | ft -auto

1 Solution

Accepted Solutions
Gidrakos
Hot Shot
Hot Shot
Jump to solution

Your best bet will probably be to sort the host array by property (MemoryUsageGB) by using the Sort-Object command, then use Select-Object to only display the top result:

Get-Cluster MyClust | Get-VMHost | Sort-Object -Property MemoryUsageGB | Select-Object -First 1

Then you can get more granular by adding another Select-Object at the end:

Get-Cluster MyClust | Get-VMHost | Sort-Object -Property MemoryUsageGB | Select-Object -First 1 | Select-Object -expandProperty Name

View solution in original post

0 Kudos
3 Replies
Gidrakos
Hot Shot
Hot Shot
Jump to solution

Your best bet will probably be to sort the host array by property (MemoryUsageGB) by using the Sort-Object command, then use Select-Object to only display the top result:

Get-Cluster MyClust | Get-VMHost | Sort-Object -Property MemoryUsageGB | Select-Object -First 1

Then you can get more granular by adding another Select-Object at the end:

Get-Cluster MyClust | Get-VMHost | Sort-Object -Property MemoryUsageGB | Select-Object -First 1 | Select-Object -expandProperty Name

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If you don't want the result to be skewed by a node that is powered off, you might want to add a Where-clause.

Get-Cluster MyClust | Get-VMHost |

where{$_.PowerState -eq 'PoweredOn'} |

Sort-Object -Property MemoryUsageGB |

Select-Object -First 1 -ExpandProperty Name


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

ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect LucD.

Thanks for your quick help.

0 Kudos