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.Login to your Azure account. After providing your credentials, the command returns information about your account.
A summary of your account is returned.
Environment : AzureCloud Account : email@example.com ...
- 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.
Returns list of available subscriptions SubscriptionName : Internal Consumption SubscriptionId : 1942a221-... TenantId : 72f988bf-... State : Enabled SubscriptionName : Microsoft Azure Internal Consumption SubscriptionId : 357e6482-... TenantId : 72f988bf-... State : Enabled
To Select a subscription, use Set-AzureRmContext command.
Set-AzureRmContext -SubscriptionID <YourSubscriptionId>
- 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 solution.New-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
- 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