Managing Azure VM using Azure PowerShell

PowerShell is a faster and more controlled tool to manage Azure VM than logging into the portal. In this post, we will look for a few commands to manage Azure VM. To run the Azure PowerShell command, first, we need to install the AzureRM module. If you want to install Azure PowerShell, see Managing Azure Subscription using Azure PowerShell.

Before triggering the Azure PowerShell command, login to an azure subscription using the command Login-AzreRMAccount. To create VM, see Provision VM using Azure PowerShell.

To list out all the VMs available in the subscription.

Get-AzureRmVM

To list out VMs from the specific resource group

Get-AzureRmVM -ResourceGroupName prod-vm

To know the public IP address of the VM.

Get-AzureRmPublicIpAddress -ResourceGroupName prod-vm

Connect to Azure VM

mstsc /v:<public ip>

To know the state of the VM

Get-AzureRmVM -ResourceGroupName prod-vm -Name win-vm1 -Status

Stop VM

Stop-AzureRmVM -ResourceGroupName prod-vm -Name win-vm1 -Force

Start VM

Start-AzureRmVM -ResourceGroupName prod-vm -Name win-vm1

Hope this post is helpful to you.