PowerShell: Removing VMware CPU/Memory resource limits

I recently assisted with a major hardware life cycle. We Migrated from Dell 1950′s to IBM BladeCenter H with H21XM blades. While the processors were comparable the RAM upgrade was tremendous. Going from 8/16GB to 32GB. This increase enabled much greater consolidation ratios, and with such we found ourselves with an abundance of hardware. After shutting down several hosts, and collapsing a few clusters we still weren’t driving our infrastructure. Shortly thereafter we realized that the resource limitations we had previously set. Were no longer necessary, and in some cases where decreasing performance (memory ballooning). A few minutes with the VI Toolkit for Windows, and we were screaming again!

# we'll use the same object to remove the limit
$ResourceAllocationInfo = New-Object VMware.Vim.ResourceAllocationInfo
$ResourceAllocationInfo.Limit = -1
 
# Get the Managed object for each VM
Foreach ($VM in get-vm | get-view) {
    # Create a fresh VirtualMachineConfigSpec
    $VirtualMachineConfigSpec = New-object VMware.Vim.VirtualMachineConfigSpec
    $i = 0
    # If the CPU Allocation is not unlimited add CPU to our spec.
    IF ($VM.ResourceConfig.CpuAllocation.Limit -ne -1) {
        $VirtualMachineConfigSpec.cpuAllocation = $ResourceAllocationIn
    	$i++
    }
    # If the Memory Allocation is not unlimited add Memory to our spec.
    IF ($VM.ResourceConfig.MemoryAllocation.Limit -ne -1) {
        $VirtualMachineConfigSpec.memoryAllocation = $ResourceAllocationInfo
        $i++
    }
    # If $I is gt 0 then we have a VM to fix... Trigger the reconfig task.
    IF ($I -gt 0) {
        write-verbose "Removing limits on $($VM.Name)"
        [void]$VM.ReconfigVM_Task($VirtualMachineConfigSpec)
    }
}


Now all that is left is for Andrew to translate this to perl/rCLI.
~Glenn