PowerShell working with Azure Resource Manager RM – Step By Step Changing RM Subscriptions

Direct answer

There are two different types resource modes in Azure. One is the Service Manager (classic) and the other is the new Resource Manager. Resource Manager is the new model and much, much better for a bunch of reasons. Those reasons are beyond the scope of this post but the way to connect to the Resource […]

There are two different types resource modes in Azure.  One is the Service Manager (classic) and the other is the new Resource Manager.   Resource Manager is the new model and much, much better for a bunch of reasons.  Those reasons are beyond the scope of this post but the way to connect to the Resource Manager is different in PowerShell that the Service Manager.  For that reason, I wanted to outline how to connect to Azure Resource Manager in Powershell.

First, in order to connect to Azure you have to have the latest version of the PowerShell Azure client which can be downloaded from the Azure download page https://azure.microsoft.com/en-us/downloads/.  Scroll down to Command-Line tools and under PowerShell  click Windows install.  I direct link is https://go.microsoft.com/?linkid=9828653&clcid=0x409  Login to your Azure account. After providing your credentials, you will be given the option to install components.  Follow the prompts.  You may require a restart when finished.

1. Add-AzureRmAccount

A summary of your account is returned.

Environment : AzureCloud

Account : someone@example.com

…

The Add-AzureRMAccount adds cached credentials to your Pwwershell session.  If you have already connected once, you can useLogin-AzureRmAccount

1. If you have multiple subscriptions, provide the subscription id you wish to use for deployment with the Set-AzureRmContext command To determine what subscriptions you have, you can use Get-AzureRmSubscription.

Get-AzureRmSubscriptionReturns list of available subscriptions

SubscriptionName : Internal Consumption

SubscriptionId : 1942a221-…

TenantId : 72f988bf-…

State : EnabledSubscriptionName : Microsoft Azure Internal Consumption

SubscriptionId : 357e6482-…

TenantId : 72f988bf-…

State : Enabled

1. You could make it a bit easier to read with a format command

Get-AzureRmSubscription | Format-table SubscriptionName,isDefault,isCurrent,DefaultAccount,subscriptionid

1. To Select a subscription, use Set-AzureRmContext command.Set-AzureRmContext -SubscriptionID

1. If you do not have an existing resource group, create a new resource group with the New-AzureRmResourceGroup command. Provide the name of the resource group and location that you need for your solutionNew-AzureRmResourceGroup -Name ExampleResourceGroup -Location “West US”A summary of the new resource group is returned.ResourceGroupName : ExampleResourceGroup

Location : westus

ProvisioningState : Succeeded

Tags :

Permissions :

Actions NotActions

======= ==========

*

ResourceId : /subscriptions/######/resourceGroups/ExampleResourceGroup

1. Notice: now when you run commands use the resource manager version of the commands. As an example instead of using Get-AzureVM you would use Get-AzureRmVM

Dan Stolts

Founder and Chief AI Officer of Just In Time AI, with an IT career that began in 1988 -- nearly four decades of experience. Over a decade of that career went into building ITProGuru into a 250,000-uniques/mo IT-community resource, and he now applies the same teach-first approach to AI systems that run real businesses. Full profile →