I'm looking for a powershell script which can pull out the following info..
Cluster Name, Total CPU, Total Memory, Total Storage, Available CPU, Available Memory and Available Storage..
I'm trying this to start with.. but doesn't seem to work for some reason.. Any other script or corrections to this script please?
$clusters = Get-Cluster | Sort Name
ForEach ($cluster in $clusters)
{
$vmhosts = Get-VMHost -Location $cluster
ForEach ($VMhostView in ($vmhosts | Get-View))
{
$TotalHostMemory += $vmhostView.Hardware.MemorySize
$TotalHostCPU += $VMhostView.Hardware.NumCpuPkgs
}
$NumHosts = ($vmhosts | Measure-Object).Count
$vms = Get-VM -Location $cluster | Where {$_.PowerState -eq "PoweredOn"}
$NumVMs = $vms.Length
$TotalRAM_GB = [math]::Round($TotalHostMemory/1GB,$digits)
$TotalVMMemoryMB = $vms | Measure-Object -Property MemoryMB -Sum
$TotalVMCPU = $vms | Measure-Object -Property NumCPU -Sum
$AssignedRAM_GB = [math]::Round($TotalVMMemoryMB.Sum/1024,$digits)
$PercentageMemUsed = [math]::Round((($TotalVMMemoryMB.Sum/1024)/($TotalHostMemory/1GB))*100)
$PercentageCPUUsed = [Math]::Round(($TotalVMCPU/$TotalHostCPU)*100)
$report = @()
$Details = "" | Select "Cluster Name", TotalCPU, TotalMemory, TotalVMs, "% Cluster Memory Used", "% Cluster CPU Used"
$Details."Cluster Name" = $Cluster.Name
$Details.TotalCPU = $TotalHostCPU
$Details.TotalMemory = $TotalHostMemory
$Details.TotalVMs = $NumVMs
$Details."% CPU Used" = $PercentageCPUUsed
$Details."% Memory Used" = $PercentageMemUsed
$report += $Details
$report | ConvertTo-Html -title "Cluster Information" -body "<H3>Cluster Information</H3>" | Out-File -Append $filelocation
Disconnect-VIServer * -Confirm:$false
}
VMSavvy