PoshCode Archive  Artifact [f8a8ebb87d]

Artifact f8a8ebb87de9cb029de5afeb05b47669a4ebdf2c85982aba2d9073c690d429cc:

  • File Set-Resource-Limits.ps1 — part of check-in [807bbcee3c] at 2018-06-10 13:24:56 on branch trunk — Set the resource limits on VMs automatically based on the number of vCPUs and vRAM assigned. This is useful as a preliminary pass at resource tiering. (user: Ed Goad size: 1200)

# encoding: ascii
# api: powershell
# title: Set Resource Limits
# description: Set the resource limits on VMs automatically based on the number of vCPUs and vRAM assigned. This is useful as a preliminary pass at resource tiering.
# version: 0.1
# author: Ed Goad
# license: CC0
# x-poshcode-id: 3392
# x-archived: 2012-05-10T14:18:02
# x-published: 2012-05-02T13:55:00
#
# This script identifies the number of vCPUs and amount of RAM assigned to a VM, then configures limits of 1000MHz per vCPU, and a reservation of 25% of the RAM.
#
Param([Parameter(Mandatory=$true)] [string]$VMGuest)

$vm = get-vm $VMGuest
$cpuCap = $vm.NumCPU*1000
$cpuRes = $cpuCap/2

$memCap = $vm.MemoryMB
$memRes = $memCap/4

$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
$spec.memoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
$spec.memoryAllocation.Shares = New-Object VMware.Vim.SharesInfo;
$spec.memoryAllocation.Limit = -1;
$spec.memoryAllocation.Reservation = $memRes;

$spec.cpuAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
$spec.cpuAllocation.Limit = $cpuCap;
$spec.cpuAllocation.Reservation = $cpuRes;

($vm | get-view).ReconfigVM_Task($spec)