Generates Hyper-V CPU allocation report
This script will generate VM resource allocation information to provide an idea of how much you have used and what is still available
Or just run it from ISE, you can also just paste the whole thing at the PowerShell prompt and press enter twice afterwards
A list of Hypervisor or cluster resoucres as well as resources used by each VM with the total per Hypervisor
This is by no means complete and is a work in progress
Microsoft Hyper-V
Hyper-V Resource Allocation

Function Get-CPUAllocation
Param ([Parameter(Mandatory=$true,Position=0)]$ComputerName)
$UsedCPU = 0
$ComputerSystem = Get-WmiObject -ComputerName $ComputerName Win32_ComputerSystem
$HypCPU = @{($ComputerSystem.Name+" CPU(s)") = $ComputerSystem.NumberOfLogicalProcessors}
$CPUobject = New-Object -TypeName PSObject -Property $HypCPU
Format-Table -InputObject $CPUobject -AutoSize
$VMs = Get-VM -ComputerName $ComputerName
foreach ($VM in $VMs)
$CPUAllocation = [ordered]@{'Name' = $VM.Name;
'CPU(s)'= $VM.ProcessorCount}
$obj = New-Object -TypeName PSObject -Property $CPUAllocation
Write-Output -InputObject $obj
$UsedCPU = $VM.ProcessorCount + $UsedCPU
$AllocatedCPU = [ordered]@{'Name'='TotalUsed';'CPU(s)'= $UsedCPU}
$UsedCPUTotal = New-Object -TypeName PSObject -Property $AllocatedCPU
Write-Output -InputObject $UsedCPUTotal

$cluster = Get-Service -Name ClusSvc -ErrorAction SilentlyContinue
if ($cluster)
Get-ClusterNode | ForEach-Object {Get-CPUAllocation -ComputerName $_.Name}
Get-CPUAllocation -ComputerName $ENV:COMPUTERNAME

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s