Skip to content

Instantly share code, notes, and snippets.

@simonjgreen
Created May 22, 2017 10:41
Show Gist options
  • Save simonjgreen/bde4c36c2b01bc01b9b81540933fc833 to your computer and use it in GitHub Desktop.
Save simonjgreen/bde4c36c2b01bc01b9b81540933fc833 to your computer and use it in GitHub Desktop.
Get the commercial value of all hosts
function getValue{
# Define the dict of our products
$productsByMem = @{}
$productsByMem.Add(0.5,40)
$productsByMem.Add(1,60)
$productsByMem.Add(2,90)
$productsByMem.Add(3,130)
$productsByMem.Add(4,160)
$productsByMem.Add(6,210)
$productsByMem.Add(8,260)
$productsByMem.Add(12,375)
$productsByMem.Add(16,500)
$productsByMem.Add(24,600)
$_ | %{
$hosts = Get-VMHost
foreach ($vmhost in $hosts) {
$row = "" | select Host, VMs, Value
$row.Host = $vmhost.Name
$value = 0
$vmCount = 0
$vms = $vmhost | Get-VM
foreach ($vm in $vms) {
$vmCount += 1
if ($vm -like "LB*") {
$value += 120
}
if ($vm -like "FW*") {
$value += 120
}
if ($vm -like "VDED*") {
$value += $productsByMem.Get_Item([int]$vm.MemoryGB)
}
}
$row.VMs = $vmCount
$row.Value = $value
$row
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment