Powershell script to list percentage of VMs present
These are just basic powershell scripts. You can use your own logic to enhance this.
#To list percentage of VMs present in each resource pool
cls
#Connect to Vcenter
Connect-VIServer -Server 172.28.xx.xx -User username -Password password
#Select the cluster from which the resource pool need to be selected. '*' represents all. Replace it with the resource pool name to be specific
$rpools = Get-ResourcePool -Location *
[int]$totalvm = $null
$rpc = $null
#Select each resource pool from the cluster
foreach($rpool in $rpools)
{
$totalvm += $rpool.ExtensionData.Vm.count
}
foreach($rpool in $rpools)
{
if($rpool.Name -ne 'Resources')
{
$rpoolc = $rpool.ExtensionData.Vm.count
$rpc = ($rpoolc / $totalvm) * 100
Write-Host "Percentage of VMs in $($rpool) : $($rpc)"
}
}
#To list percentage of VMs present in each resource pool
cls
#Connect to Vcenter
Connect-VIServer -Server 172.28.xx.xx -User username -Password password
#Select the cluster from which the resource pool need to be selected. '*' represents all. Replace it with the resource pool name to be specific
$rpools = Get-ResourcePool -Location *
[int]$totalvm = $null
$rpc = $null
#Select each resource pool from the cluster
foreach($rpool in $rpools)
{
$totalvm += $rpool.ExtensionData.Vm.count
}
foreach($rpool in $rpools)
{
if($rpool.Name -ne 'Resources')
{
$rpoolc = $rpool.ExtensionData.Vm.count
$rpc = ($rpoolc / $totalvm) * 100
Write-Host "Percentage of VMs in $($rpool) : $($rpc)"
}
}
Comments
Post a Comment