Hello All,
I'm having having difficulties to create a script that will give me the following:
Cluster CPU, Memory and vSAN Usage. Number of hosts, number of VMs
Needs to export as html and collect the information from multiple vcenter.
Would be something like
Total CPU, CPU Usage, CPU Free, Total RAM, RAM Usage, RAM Free, Total Capacity, Used Capacity, Free Capacity, N° Hosts, N°VMs
I have this, but i need it at the cluster level, i think is easier, but you know more than me :)
$Output =@();
$hosts = @();
Connect-VIServer$hosts -User "ey\a2139242-3" -Password "F3#~5ct7~kdYxNm"
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "TD{border-width: 1px;padding: 1px;border-style: solid;border-color: black;background-color:white}"
$a = $a + "</style>"
Write-Host ("Getting Cluster Information from $hosts")
$vcenters| % {
$cluster =Get-cluster -Name *VSAN*
get-cluster$cluster | get-vmhost | % {
$vmhost =$_
$VMHostView = $VMHost | Get-View
$VMs = $VMHost | Get-VM#| ? { $_.PowerState -eq "PoweredOn" }
$TotalRAMGB = [math]::round($vmhost.MemoryTotalGB)
$TotalRAMUsageGB = [math]::round($vmhost.MemoryUsageGB)
$TotalRAMfreeGB = [math]::round($TotalRAMGB-$TotalRAMUsageGB)
$PercRAMUsed = [math]::round(($TotalRAMUsageGB/$TotalRAMGB)*100)
$TotalRAMReservedFree = [math]::round(($TotalRAMGB/100)*15)
$TotalRAMAvailable = [math]::round(($TotalRAMfreegb-$totalramreservedfree))
$temp = New-Object PSObject
$temp | Add-Member -pass NoteProperty "VMhost"$vmhost.Name
$temp | Add-Member -pass NoteProperty "ClusterName"$cluster.name
$temp |Add-Member -pass NoteProperty Sockets $VMHostView.Hardware.cpuinfo.NumCPUPackages
$temp |Add-Member -pass NoteProperty Cores $VMHostView.Hardware.cpuinfo.NumCPUCores
$temp |Add-Member -pass NoteProperty Threads $VMHostView.Hardware.cpuinfo.NumCPUThreads
$temp |Add-Member -pass NoteProperty VMCount (($VMs | measure-object).Count)
$temp |Add-Member -pass NoteProperty vCPU (0 + ($VMs | measure-object -Sum NumCPU).Sum)
$temp |Add-Member -pass NoteProperty vCPUperCore ((0 + ($VMs | measure-object -Sum NumCPU).Sum)/$VMHostView.Hardware.cpuinfo.NumCPUCores)
$temp |Add-Member -pass NoteProperty "RAMGB"$TotalRAMGB
$temp |Add-Member -pass NoteProperty "RAMUsageGB"$totalramusageGB
$temp |Add-Member -pass NoteProperty "RAMFreeGB"$totalramfreeGB
$temp |Add-Member -pass NoteProperty "RAMUsage%"$PercRAMused
$temp |Add-Member -pass NoteProperty "RAMReservedGB(15%)"$totalramreservedfree
$temp |Add-Member -pass NoteProperty "RAM Available for NEW VMs in GB"$totalramavailable
$Output+=$temp
}
}
$Output | ConvertTo-Html -Head $a | Out-File C:\Users\nicolas.porta\Desktop\xrails_hosts.htm -width 400
Disconnect-VIServer * -confirm:$false