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
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
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
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.
where{$_.PowerState -eq 'PoweredOn'} |
Sort-Object -Property MemoryUsageGB |
Select-Object -First 1 -ExpandProperty Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect LucD.
Thanks for your quick help.