[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

Get Hyper-V Cluster Summary Overview in Powershell

I am interested in getting the Hyper-V Cluster Summary Overview in Powershell, more specifically the  average memory usage on the hosts. I haven't found any info that has lead me to my goal by Googling. Do you guys have any tips?
This is Hyper-V on Windows 2012 R2.
0
itnifl
Asked:
itnifl
1 Solution
 
Shabarinath RamadasanInfrastructure Specialist - MicrosoftCommented:
Hi itnifl,

Here is my script for getting the overall summary of HyperV infrastructure.
It will cover VM, Storage, Physical host etc.

Try it out.

http://gallery.technet.microsoft.com/scriptcenter/HyperV-Dash-Board-VM-Disk-299bac7d

Good luck !
Shaba
0
 
itniflAuthor Commented:
Thank you. From your script i extracted the following and added a few lines to suit my needs:

Function GetClusterFillingDegree {
	param([string] $ClusterName)

	Import-Module -Name VirtualMachineManager
	
	$props = @{
		errorID = 0;
    }

	[array] $cNodes = Get-Cluster $ClusterName|Get-ClusterNode |Where {$_.state -eq "Up"} |Select Name
	$nodecount = $cNodes.length
	[array] $hostDetails = Get-Cluster $ClusterName|Get-ClusterNode|Select name, @{Label="TotalPhysicalMemory"; Expression={[int]""}}, @{Label="AvailablePhysicalMemory"; Expression={[int]""}}, @{Label="AvailablePhysicalMemoryPC"; Expression={[int]""}}, @{Label="TotalVMStartupRamAllocated"; Expression={[int]""}}, @{Label="TotalVMMaxMemoryAllocated"; Expression={[int]""}}, @{Label="Processors"; Expression={[int]""}}, @{Label="ProcessorCore"; Expression={[int]""}}, @{Label="LogicalProcessors"; Expression={[int]""}}, @{Label="vProcessors"; Expression={[int]""}}, @{Label="HostMemoryHealth"; Expression={[int]""}}, @{Label="VMs"; Expression={[int]""}}
	For ($i=0; $i -lt $nodecount; $i++)
			{
		#Write-Host ("Processing Hyper-V Host "+$cNodes.Name[$i]) -Foregroundcolor Green -BackgroundColor DARKGREEN
		$hDetails = Get-WmiObject -Class win32_OperatingSystem -ComputerName $cNodes.Name[$i] |Select FreePhysicalMemory, TotalVisibleMemorySize
		[int] $hostDetails[$i].TotalPhysicalMemory =  ((($hDetails).TotalVisibleMemorySize)/1048576)
		[int] $hostDetails[$i].AvailablePhysicalMemoryPC  =  (((($hDetails).FreePhysicalMemory)/(($hDetails).TotalVisibleMemorySize))*100)
		[int] $hostDetails[$i].AvailablePhysicalMemory =  ((($hDetails).FreePhysicalMemory)/1048576)
		If (($hostDetails[$i].AvailablePhysicalMemoryPC -le "10") -OR ($hostDetails[$i].AvailablePhysicalMemory -lt "5"))
			{
			[int] $hostDetails[$i].HostMemoryHealth = "3"
			}
		ElseIf ((($hostDetails[$i].AvailablePhysicalMemoryPC -le "20") -And ($hostDetails[$i].AvailablePhysicalMemoryPC -gt "10")) -OR (($hostDetails[$i].AvailablePhysicalMemory -lt "10") -And ($hostDetails[$i].AvailablePhysicalMemory -gt "5")))
			{
			[int] $hostDetails[$i].HostMemoryHealth = 2
			}
		ElseIf ((($hostDetails[$i].AvailablePhysicalMemoryPC -le "30") -And ($hostDetails[$i].AvailablePhysicalMemoryPC -gt "20")) -OR (($hostDetails[$i].AvailablePhysicalMemory -lt "20") -And ($hostDetails[$i].AvailablePhysicalMemory -gt "10")))
			{
			[int] $hostDetails[$i].HostMemoryHealth = 1
			}
		Else
			{
			[int] $hostDetails[$i].HostMemoryHealth = 0
			}
		$procDetails = Get-WmiObject -Class Win32_Processor -Computername $cNodes.Name[$i]
		$hostDetails[$i].Processors = ($procDetails.DeviceID).Count
		$hostDetails[$i].ProcessorCore = ($procDetails.numberofcores |Measure-Object -Sum).sum
		$hostDetails[$i].LogicalProcessors = ($procDetails.numberoflogicalprocessors |Measure-Object -Sum).sum
	}
	$TotalPhysicalMemory = 0
	$AvailablePhysicalMemory = 0
	$hostDetails | % {
		$TotalPhysicalMemory += $_.TotalPhysicalMemory
		$AvailablePhysicalMemory += $_.AvailablePhysicalMemory
	}
	
	$fillingDegree = 1-$AvailablePhysicalMemory/$TotalPhysicalMemory	
	$props.Add("fillingDegree", $fillingDegree);	
	return new-object PSCustomObject –property $props
}

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now