Book Image

Azure PowerShell Quick Start Guide

By : Thomas Mitchell
Book Image

Azure PowerShell Quick Start Guide

By: Thomas Mitchell

Overview of this book

As an IT professional, it is important to keep up with cloud technologies and learn to manage those technologies. PowerShell is a critical tool that must be learned in order to effectively and more easily manage many Azure resources. This book is designed to teach you to leverage PowerShell to enable you to perform many day-to-day tasks in Microsoft Azure. Taking you through the basic tasks of installing Azure PowerShell and connecting to Azure, you will learn to properly connect to an Azure tenant with PowerShell. Next, you will dive into tasks such as deploying virtual machines with PowerShell, resizing them, and managing their power states with PowerShell. Then, you will learn how to complete more complex Azure tasks with PowerShell, such as deploying virtual machines from custom images, creating images from existing virtual machines, and creating and managing of data disks. Later, you will learn how to snapshot virtual machines, how to encrypt virtual machines, and how to leverage load balancers to ensure high availability with PowerShell. By the end of this book, you will have developed dozens of PowerShell skills that are invaluable in the deployment and management of Azure virtual machines.
Table of Contents (7 chapters)

VM power states

If you manage any number of Azure VMs on a day-to-day basis, you are going to need to understand the different states in which VMs can exist. In this section, I want to briefly touch on the available power states for a VM, and on how to check the current power state of a VMe via PowerShell.

There are seven power states that a VM can exist in:

  • Starting: Indicates that the VM is being started.
  • Running: Indicates that the VM is running.
  • Stopping: Indicates that the VM is being stopped.
  • Stopped: Indicates that the VM is stopped. Note that VMs in the stopped state still incur compute charges.
  • Deallocating: Indicates that the VM is being deallocated.
  • Deallocated: Indicates that the VM is completely removed from the hypervisor but still available in the control plane. VMs in the deallocated state do not incur compute charges.
  • Unknown ( - ): Indicates that the power state of the VM is unknown.

Although most of these are self-explanatory, I wanted to ensure that you were aware of them.

Retrieving the VM's status

Retrieving the status of a VM is rather straightforward. To retrieve the state of a specific virtual machine, use the Get-AzureRmVM command, taking care to specify valid names for the VM and the resource group.

Run the following command to check the status of the myVM virtual machine:

Get-AzureRmVM `
-ResourceGroupName "VMLab" `
-Name "myVM" `
-Status

The command in the preceding example retrieves the current status of the myVM virtual machine. While the output will include quite a bit of information, what we are most concerned about for this exercise is the part that shows whether the VM is running:

The resulting output indicates the current status of the VM.