VMware Cloud Community
VicMware
Contributor
Contributor
Jump to solution

script that gives the host name with most CPU and memory resources available

Hi

Does anyone has a script that gives the host name with most CPU and memory resources available in the cluster?

Regards

Vickie

Reply
0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, VicMware-

You can get the host with the most free CPU resources, or with the most free memory, using the following:

## get the host with the most free CPU cycles
Get-Cluster myCluster0 | Get-VMHost | Select-Object Name,
    @{n
="CpuMhzFree"; e={$_.CpuTotalMhz - $_.CpuUsageMhz}} | Sort-Object -Property CpuMhzFree -Descending | Select -First 1

## get the host with the most free memory
Get-Cluster myCluster0 | Get-VMHost | Select-Object Name,
    @{n
="MemGBFree"; e={$_.MemoryTotalGB - $_.MemoryUsageGB}} | Sort-Object -Property MemGBFree -Descending | Select -First 1

The first would output something like:

Name          CpuMhzFree
----          ----------
myVMHost0          25384

And the latter would output:

Name           MemGBFree
----           ---------
myVMHost4        122.323

...where each of those hosts are the ones in the cluster with the most free CPU/memory, respectively.  That get the things for which you are looking?

View solution in original post

Reply
0 Kudos
1 Reply
mattboren
Expert
Expert
Jump to solution

Hello, VicMware-

You can get the host with the most free CPU resources, or with the most free memory, using the following:

## get the host with the most free CPU cycles
Get-Cluster myCluster0 | Get-VMHost | Select-Object Name,
    @{n
="CpuMhzFree"; e={$_.CpuTotalMhz - $_.CpuUsageMhz}} | Sort-Object -Property CpuMhzFree -Descending | Select -First 1

## get the host with the most free memory
Get-Cluster myCluster0 | Get-VMHost | Select-Object Name,
    @{n
="MemGBFree"; e={$_.MemoryTotalGB - $_.MemoryUsageGB}} | Sort-Object -Property MemGBFree -Descending | Select -First 1

The first would output something like:

Name          CpuMhzFree
----          ----------
myVMHost0          25384

And the latter would output:

Name           MemGBFree
----           ---------
myVMHost4        122.323

...where each of those hosts are the ones in the cluster with the most free CPU/memory, respectively.  That get the things for which you are looking?

Reply
0 Kudos