Mir stellt sich im Administrations-Alltag immer wieder die Frage, welcher unserer Hyper-V-Hosts derzeit am besten für eine neue VM geeignet ist (Nein, wir verwenden leider kein VMM…). Anstatt aber dabei jedes Mal jeden Host hinsichtlich seiner freien Ressourcen “abzuklappern”, habe ich mir ein entsprechendes PowerShell-Skript geschrieben, was eine passende Function bereithält. Ihr könnt das Skript gerne für eure Zwecke anpassen oder direkt so übernehmen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | $AllHyperVHosts = "HostNr1","HostNr2","HostNr3" function Get-HyperVHostInfo([string]$HyperVHost) { $vCores = ((Get-VM -ComputerName $HyperVHost).ProcessorCount | Measure-Object -Sum).Sum $Property = "numberOfCores", "NumberOfLogicalProcessors" $CPUs = Get-Ciminstance -class Win32_Processor -Property $Property -ComputerName $HyperVHost| Select-Object -Property $Property $Cores = ($CPUs.numberOfCores | Measure-Object -Sum).Sum $logCores = ($CPUs.NumberOfLogicalProcessors | Measure-Object -Sum).Sum $os = Get-Ciminstance Win32_OperatingSystem -ComputerName $HyperVHost $MemFreePct = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2) $object = New-Object -TypeName PSObject $object | Add-Member –MemberType NoteProperty –Name PhysicalCores –Value $Cores $object | Add-Member –MemberType NoteProperty –Name LogicalCores –Value $logCores $object | Add-Member –MemberType NoteProperty –Name VirtualCores –Value $vCores $object | Add-Member –MemberType NoteProperty –Name MemTotalGB -Value ([int]($os.TotalVisibleMemorySize/1mb)) $object | Add-Member –MemberType NoteProperty –Name MemFreeGB -Value ([math]::Round($os.FreePhysicalMemory/1mb,2)) $object | Add-Member –MemberType NoteProperty –Name MemFreePct -Value $MemFreePct Return $object } ForEach($OneHost in $AllHyperVHosts) { $HostData = Get-HyperVHostInfo -HyperVHost $OneHost Write-Host "$OneHost has $($Hostdata.PhysicalCores) physical cores, $($Hostdata.LogicalCores) logical cores and $($Hostdata.VirtualCores) virtual cores are used in all VMs overall." -ForegroundColor Yellow Write-Host "The Core:vCore ratio is `t`t1:$([math]::Round(($Hostdata.VirtualCores) / ($Hostdata.PhysicalCores),2))" Write-Host "The Log.Core:vCore ratio is `t1:$([math]::Round(($Hostdata.VirtualCores) / ($Hostdata.LogicalCores),2))" Write-Host "The system has $($Hostdata.MemFreeGB)GB of free memory and $($Hostdata.MemTotalGB)GB memory at all, which is $($Hostdata.MemFreePct)% free" Write-Host "" } Write-Host "The conservative approach for logical cores is `t1:8 " |
Eine Beispielausgabe sieht dann so aus: