Reader small image

You're reading from  Azure PowerShell Quick Start Guide

Product typeBook
Published inDec 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789614954
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Thomas Mitchell
Thomas Mitchell
author image
Thomas Mitchell

Thomas Mitchell is a 25+ year veteran of the IT industry and carries numerous industry certifications. He has built a rather in-depth skill set that spans numerous IT disciplines. Tom's disciplines include Microsoft Exchange, Microsoft Office 365, Microsoft Azure, and Active Directory. He is now an independent IT consultant, a freelance author, and online IT trainer, has written about numerous IT topics for several online publications, and has even published several of his own IT courses on Udemy (dot) com. You can find a complete list of his courses at thomasmitchell (dot) net/udemy. Tom is the managing editor for understandingazure (dot) com. He lives with his wife, Darlene, and five kids, Michael, Tommy, Joey, Brittany, and Matthew.
Read more about Thomas Mitchell

Right arrow

Resizing a VM with PowerShell

There will be times when an application will require more resources than it once did. In cases such as these, an Azure VM can be resized.

Resizing a VM requires the use of two different PowerShell commands. The first command, called Get-AzureRmVMSize, is used to retrieve a list of VM sizes available in a chosen region. Before resizing a virtual machine, you must ensure that whatever size you want to change the virtual machine to is available in the virtual machine's region. The Get-AzureRmVMSize command does exactly this.

The second command that is required the Update-AzureRmVM command. This command is used to update a VM after changing its size configuration.

Resizing a VM

In this section, you are going to resize the myVM virtual machine that you created earlier. However, before attempting to do so, you will need to retrieve a list of VM sizes available in the EastUS region, which is where the myVM virtual machine resides.

To complete this task, run the following command from PowerShell:

Get-AzureRmVMSize -Location "EastUS"

The preceding command should return quite a few sizes. Confirm that Standard DS2_V2 is available. If it's not, find another size that is available.

After confirming that Standard DS2_V2 (or your chosen size) is available, you can use PowerShell to resize the myVM virtual machine:

After confirming that Standard DS2_V2 is available in the EastUS region, you also need to make sure that it's available on the current cluster where the myVM virtual machine resides. To do so, use the same Get-AzureRmVMSize command as before—just with a few different switches.

To confirm that the Standard DS2_V2 size (or your chosen size) is available on the cluster where myVM resides, run the following command:

Get-AzureRmVMSize -ResourceGroupName "VMLab" -VMName "myVM"

By specifying the -VMName and -ResourceGroupName switches in the preceding command, you can confirm that the Standard DS2_V2 size is available on the same cluster as the VM. If so, the virtual machine can be resized from a powered-on state (without the need to deallocate it). However, it will still require a reboot during the operation:

If the Standard DS2_V2 size is not available on the VM's current cluster, the virtual machine needs to first be deallocated before the resize operation can occur. In such a case, any data on the temp disk is removed and the public IP address will change (unless a static IP address is being used).

To resize the virtual machine (myVM), you need to run a few different PowerShell commands.

The first command essentially loads the configuration profile of the VM into a variable called $vm. The second command will modify the -VMSize attribute stored in that variable to reflect the new VM size. The third command, called Update-AzureRmVM, will take the updated configuration that is stored in the $vm variable and write it to the VM.

To begin the resize process of the myVM virtual machine, run the following command from a PowerShell session that's connected to your Azure tenant:

$vm = Get-AzureRmVM -ResourceGroupName "VMLab" -VMName "myVM"

The preceding command retrieves the current VM information and stores it in the $vm variable.

To modify the size attribute for the VM, run the following command:

$vm.HardwareProfile.VmSize = "Standard_DS2_V2"

The previous command changes the size attribute of the myVM virtual machine that's stored in the variable to Standard DS2_V2.

Once the new size has been specified using the preceding command, run the following command to update the VM:

Update-AzureRmVM -VM $vm -ResourceGroupName "VMLab"

After executing the preceding Update-AzureRmVM command, the myVM virtual machine is updated and then automatically restarted:

The process takes a few minutes to complete, but when it completes, the myVM virtual machine is resized to reflect the new size.

Previous PageNext Page
You have been reading a chapter from
Azure PowerShell Quick Start Guide
Published in: Dec 2018Publisher: PacktISBN-13: 9781789614954
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Thomas Mitchell

Thomas Mitchell is a 25+ year veteran of the IT industry and carries numerous industry certifications. He has built a rather in-depth skill set that spans numerous IT disciplines. Tom's disciplines include Microsoft Exchange, Microsoft Office 365, Microsoft Azure, and Active Directory. He is now an independent IT consultant, a freelance author, and online IT trainer, has written about numerous IT topics for several online publications, and has even published several of his own IT courses on Udemy (dot) com. You can find a complete list of his courses at thomasmitchell (dot) net/udemy. Tom is the managing editor for understandingazure (dot) com. He lives with his wife, Darlene, and five kids, Michael, Tommy, Joey, Brittany, and Matthew.
Read more about Thomas Mitchell