We recently needed to calculate the number of physical CPUs in use by hosts running Windows VMs in order to work out how many Windows Server 2008 Data Center Edition licenses we require.
Data Center (DC) edition permits you to run as many Windows Server VMs as you like on a host which has the DC license. You don’t actually need to install the Datacenter software, so you can use this license on a host running vSphere or Xen (as well as Hyper-V).
Not all of our hosts need a DC license as some don’t run any Windows VMs, and other run a smaller number where it’s cheaper either to use an Enterprise license (up to 4 VMs) or license VMs individually. To mark which hosts need a DC license, I create a Custom Attribute called “DC SPLA” for all hosts, with values of “Yes”,”No”, or “?” (where it wasn’t clear what license was appropriate).
I then created a small PowerCLI script which dumps out a CSV file containing all hosts which were possible DC license uses (those which were marked “Yes” or “?”), along with the number of physical CPUs in each host.
It’s a short script and isn’t particularly special but I’m posting it anyway.
$vcentername = "myvcentername.net"
$outputfile = "c:\users\myname\Desktop\cpucount.csv"
Connect-VIServer $vcentername
get-vmhost | ForEach-Object {
if ((Get-annotation -Entity $_ -CustomAttribute "DC SPLA" | select -ExpandProperty value ) -ne "No")
{
New-Object -TypeName PSobject -Property @{
HostName = $_.name
CpuCount = (Get-View $_.ID).Hardware.CpuInfo.NumCpuPackages
}| Select-Object Hostname,CpuCount
}
} | export-csv -Path $outputfile
Disconnect-VIServer $vcentername -Confirm:$false