≡ Menu

Increase/Decrease Virtual Machine Memory using PowerShell

This article will help you understanding how to configure Memory (both static and Dynamic) on a Hyper-V Virtual machine. You can increase or decrease memory using the PowerShell scripts given in this article.

Ever since I am running my test lab on Windows Server 2012 Datacentre edition, I have been playing with various options in the OS and especially Hypervisor. I have multiple VMs running in the Hypervisor and today I wanted to increase Memory of one of my virtual machine name Infra2. I know it is very easy to do it from Hyper-V Manager but my love towards PowerShell won’t let me do that way. So started looking at options for increasing memory of my virtual machine from 1GB to 2GB using PowerShell code.

The Hyper-V PowerShell module in Windows Server 2012 has two cmdlets for adjusting the memory configuration of Virtual Machines. One is Set-VM and another is Set-VMMemory. While the first one is used for modifying any configuration of Virtual Memory, second one is explicitly designed to change memory configuration. In this article I will focus on Set-VM cmdlet.

Windows Server 2012 Hyper-V comes with Dynamic Memory concept. If you haven’t heard about it, you can try this TechNet page for more details. Using Set-VM cmdlet, we can set both Dynamic and static Memory of virtual machine. Let us start looking into some of the examples.

First let us see how to check the current memory configuration. Using Get-VM cmdlet we can see what is the current memory assignment, whether it is static or dynamic memory, if dynamic memory what is the max and min values.

Get-VM -Name Infra2 | select *Memory*

Virtual Machine Memory Change Powershell

The above output is pretty much self-descriptive. I want you to make a note of DynamicMemoryEnabled property value. If it is true, you have dynamic memory enabled. A False value like shown in above screen indicates that it’s a static assignment. In case of static assignment, MemoryStatup is the value that we need to focus. The value stored in this property is bytes.

So, now let us go ahead and see how to change the memory of this VM from 1GB (1073741824 in bytes) to 2GB. It is as simple as executing below command.

Set-VM -StaticMemory -Name Infra2 -MemoryStartupBytes 2GB

Now you verify your memory values again using Get-VM cmdlet and you will see new value in the MemoryStartup property.

Similarly, if you want to increase memory values in case of Dynamic memory, just do your math and come up with what values to you want to give for MemoryStartup, MemoryMinimum, MemoryMaximum properties and assign them like shown below. In the below example, I want my VM to start up with 1GB of RAM and can utilize up to 2GB and minimum value is 500MB.

Set-VM -Name Infra2 -MemoryStartupBytes 1GB -MemoryMinimumBytes 500MB -MemoryMaximumBytes 2GB

Hope this article helps and happy reading…

{ 0 comments… add one }

Leave a Comment