Identify VM’s running status in Azure Resource Manager

Unlike classic model, there is no direct cmdlet to know the status for virtual machine provisioned using resource manager model. We can use the following commands to know the status of a particular virtual machine:

$resourceGroupName = "sharepointvms"
$vmName = "indspstd01"
$vmStatuses = $(Get-AzureRmVM -ResourceGroupName $resourceGroupName -VMName $vmName -Status).Statuses
foreach($vmStatus in $vmStatuses){
 if($vmStatus.Code -ne "ProvisioningState/succeeded")
 {
 Write-Output "$vmName status is `"$($vmStatus.displaystatus)`""
 }
}

Replace the value of …Continue Reading

Enable PowerShell remoting on Azure RM virtual machines

PowerShell remoting is useful to manage virtual machines using PowerShell. When you create a virtual machine in the classic azure model, a winrm endpoint is automatically configured and can be used to manage virtual machines. You’ll just need to import ssl on your local machine and connect to the remoting session. However, same is not created if you create a virtual machine in the resource manager model. So if you try to connect using PowerShell remoting for azure rm vm, you’ll see …Continue Reading

Deleting Azure Virtual Machines

Like other things, there are more than one way to delete Azure Virtual Machines. However with nearly all of them, you have a choice whether you want to delete vhds for the virtual machines or not. Sometimes it may be helpful to retain the disks for later use.

For delete virtual machine from classic portal, use below command:

$name = "mailserver01"
$serviceName = "mailsouthasia"
Remove-AzureVM -Name $name -ServiceName $serviceName

If we need to delete vhds as well, use below …Continue Reading

Using Azure Automation to stop/start virtual machines

Today, we’ll see how we can leverage Azure Automation to stop/start virtual machines in Azure.¬†We’ll begin with how to start virtual machine first and same steps can be applied to stop virtual machines. You’ll only need to change few commands in the runbook associated.

Login into Azure Resource Manager with your credentials. Click on Azure Automation account and then click on the runbooks section highlighted …Continue Reading

Get Azure virtual machine extensions

Azure virtual machines have a variety of built-in extensions that can enable configuration management. There are two extensions for Windows PowerShell. The custom script extension allows you to run a script on a virtual machine at provisioning time or after it is running. The Windows PowerShell DSC Extension allows you to define the state of a virtual machine using the PowerShell Desired State Configuration language and apply it. There are also extensions that allow you to configure your virtual machines to use open source configuration management utilities such as Chef or Puppet …Continue Reading