ganapa2000
Enthusiast
Enthusiast

Get-VMhost with less memory used

Jump to solution

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

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

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
LucD
Leadership
Leadership

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
Enthusiast
Enthusiast

Perfect LucD.

Thanks for your quick help.

0 Kudos