Just before the holidays we’ve got a small PowerCLI onliner for you. Nothing fancy, but still useful.

There are times that your virtual machine doesn’t have enough memory. Yes, you can go into the vSphere Client to change the memory configuration, but where is the fun in that?  Why not do everything from the command line? And preferably by the use of PowerCLI?

This oneliner will add memory to a specific virtual machine.

You get prompted if you’re sure that you want to change the VM.

If you want to specifiy less than a GB you still use the -MemoryGB parameter, but with a decimal:

This cmdlet will give your virtual machine 768 MB memory.

Before adding memory with PowerCLI

Of course you want to know how much memory your virtual machine has before you add something to it. To accomplish this you use the following:

Or, if you want a list of all VMs with their names and memory configuration:

How about reducing memory?

Ofcourse, you also can reduce memory, just set the memory to something lower than the machine already has. For this the machine has to be powered off

This online shuts down the virtual machine and set its memory to 256MB.

Some tricks with PowerCLI and Memory

Now that you can get and change the memory of a virtual machine from the command line you can do all kinds of crazy things with it. With one command you can double the memory

Or set the memory of one VM to the same value as another VM.

The Sky is the limit.