Monday, October 30, 2017

Basic Capacity Information (PowerCLI)

The PowerCLI cmdlets can be used to give a quick overview of the number of hosts and VMs that exist within the Virtual Center; it could be useful to record these figures on a monthly basis so that the growth of the environment can be tracked over time. How about finding the average number of VMs per host in a cluster? Again, a useful figure to regularly record so as to observe what consolidation ratios are being achieved and to plan for future capacity needs, and a figure which PowerCLI can help you find.
In the code below, we retrieve the ESX / ESXi hosts & VMs and observe their count; note the use of the $DefaultVIServer variable, which is updated each time a connection is made to a vCenter.
For the average number of VMs in each cluster, we find the total number of ESX / ESXi hosts and VMs and perform some basic maths to arrive at a figure. Note the use of some basic .NET [math]::round code and the number of decimal places (1) required to format the output as desired:

# Total number of hosts
$TotalVMHosts = (Get-VMHost).Count
Write-Host "There are $TotalVMHosts Hosts in $DefaultVIServer"
 
# Total number of guests
$TotalVMs = (Get-VM).Count
Write-Host "There are $TotalVMs Virtual Machines in $DefaultVIServer"
 
# Average VMs Per Cluster
$Clusters = Get-Cluster
foreach ($Cluster in $Clusters){
 
    $VMHosts = Get-Cluster $Cluster | Get-VMHost
    $VMs = Get-Cluster $Cluster | Get-VM
 
    $AverageVMsPerCluster = [math]::round(($VMs.count / $VMHosts.count), 1)
    Write-Host "$Cluster has $AverageVMsPerCluster guests per VMware host"
 

No comments:

Post a Comment

Vmware NSX SSL creation 

Using OpenSSL for NSX Manager SSL import: Creates CSR and 4096 bit KEY Creating NSX 6.4.2 SSL    openssl req -out nsxcert.csr -newkey rsa:40...