VMware Cloud Community
esxi1979
Expert
Expert

remove memory reservation

Hi

PowerCLI C:\> Get-VM  xxx | Get-VMResourceConfiguration | Select-Object Name,  CpuReservationMhz, MemReservationMB

Name CpuReservationMhz MemReservationMB

---- ----------------- ----------------

                     0             8192

i was able to remove cpu reservation with below

foreach ($line in $csv)
{

Get-VM $($line.name) |% {Get-View $_.ID} | % {

  $spec = new-object VMware.Vim.VirtualMachineConfigSpec;

  $spec.CPUAllocation = $_.ResourceConfig.CpuAllocation

  $spec.CpuAllocation.Reservation = 0;

  $_.ReconfigVM_Task($spec)

}

}

but it does not work for memory

for me even below did not work

1

Get-VM | Get-VMResourceConfiguration | where {$_.MemLimitMB -ne '-1'} | Set-VMResourceConfiguration -MemLimitMB $null

below did not work too

$VMs = Get-Cluster | Get-VM

Foreach ($VM in $VMs)

{

$configspec = New-Object VMware.Vim.VirtualMachineConfigSpec

$configspec.MemoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo

# This will uncheck the box.

$configspec.MemoryReservationLockedToMax = $false

# This will put the reservation back to 0

$configspec.MemoryAllocation[0].Reservation = 0

$VM.ExtensionData.ReconfigVM($ConfigSpec)

}

i tried below too

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.memoryReservationLockedToMax = $true

(Get-VM xxx).ExtensionData.ReconfigVM_Task($spec)

no luck

Please  help

0 Kudos
2 Replies
esxi1979
Expert
Expert

i think below worked for me

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.memoryReservationLockedToMax = $false

$spec.memoryAllocation = New-Object VMware.Vim.ResourceAllocationInfo

$spec.memoryAllocation.Reservation = 0

0 Kudos
LucD
Leadership
Leadership

This should work as well

foreach($line in $csv){

    Get-VM -Name $line.Name | Get-VMResourceConfiguration |

    Set-VMResourceConfiguration -CpuReservationMhz 0 -MemReservationGB 0 -Confirm:$false

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos