Over a million developers have joined DZone.

Step-by-Step: Managing Azure Resources With Azure Resource Manager (ARM) and PowerShell

How to manage your cloud environments after provisioning.

· Cloud Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database on AWS. Try it now! Brought to you in partnership with MongoDB.

In the past few articles, we’ve been focusing on provisioning end-to-end IaaS environments on the Microsoft Azure cloud platform using the new Azure Resource Manager API and PowerShell.  In this article, we’ll be looking at several ways to manage these environments post-provisioning using some of the new capabilities, such as Resource Groups and Tags, that ARM provides.

Managing Azure Resources with Azure Resource Manager and PowerShell

Before You Begin …

If you haven’t been following along with prior articles, here’s a few articles that you should review before continuing on with this article, because they provide a foundation on which this article is based:

At a minimum, you’ll need to complete the first article above before proceeding with this article.  When you’ve finished that, come back here to pick up with managing the resources you’ve provisioned.

Get All Resources in a Resource Group

In ARM, Resource Groups give us the ability to logically group related resources for monitoring, administration tasks and usage tracking.  Let’s first generate a list of all resources within a particular resource group:

# Switch to Azure Resource Manager mode

Switch-Mode `
    -Name AzureResourceManager

# Select an Azure Resource Group

$rgName = `
    (Get-AzureResourceGroup).ResourceGroupName |
    Out-GridView `
        -Title "Select a Resource Group" `

# Get all Azure Resources within Resource Group

Get-AzureResource `
    -ResourceGroupName $rgName `
    -OutputObjectFormat New |
    Select-Object `

Click to zoom ...

In the output above, you may notice that Resource Groups can group together:

  • Different types of resources (ie., Network, Compute and Storage)
  • Resources located in different Azure datacenter regions

This provides a great deal of flexibility when using Resource Groups as logical “containers” for managing complex global application workloads.

Get Azure Resources by Tags

ARM also provides the ability to tag resources with one or more custom tag values.  This can be useful to tag certain resources related to a common project, department or cost center, even if those resources don’t exist in the same Resource Group.

# Get Azure Resources by Tag

Get-AzureResource `
    -TagName "project" `
    -TagValue "demo" `
    -OutputObjectFormat New |
    Select-Object `

In this example, we returned all resources tagged with a common project value, regardless of the Resource Group in which those resources were originally provisioned.

Get All Properties of Resources in a Resource Group

# Get properties of all VMs in a Resource Group

$vm = (Get-AzureResource `
    -ResourceGroupName $rgName `
    -ResourceType "Microsoft.Compute/virtualMachines" `
    -OutputObjectFormat New `


# Get VM OS Profile


# Get VM Hardware Profile


# Get Storage Profile

$vmStorage = $vm.StorageProfile



# Get VM Network Info

$vmNetwork = $vm.NetworkProfile

$vmNetwork.NetworkInterfaces.Id |
    ForEach-Object {
    } |
    ForEach-Object {
        Get-AzureNetworkInterface `
        -Name $_ `
        -ResourceGroupName $rgName

Check Status of All VMs in a Resource Group

# Check the status of all VMs in a Resource Group

Get-AzureResource `
    -ResourceGroupName $rgName `
    -ResourceType "Microsoft.Compute/virtualMachines" `
    -OutputObjectFormat New |
Get-AzureVM `
    -Status |
Select-Object `

Stop & Start All VMs in a Resource Group

# Stop all VMs within a Resource Group

Get-AzureResource `
    -ResourceGroupName $rgName `
    -ResourceType "Microsoft.Compute/virtualMachines" `
    -OutputObjectFormat New |
Stop-AzureVM –Force

# Start all VMs within a Resource Group

Get-AzureResource `
    -ResourceGroupName $rgName `
    -ResourceType "Microsoft.Compute/virtualMachines" `
    -OutputObjectFormat New |

To Be Continued …

I hope this article was helpful in getting you started with basic management of Azure resources via the new Azure Resource Manager API and PowerShell.  In future articles, we’ll be covering additional management topics, so be sure to let us know which tasks you are most interested in learning more about.

Until then … See you in the Clouds!

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

cloud ,azure

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}