Are the Azure subscriptions tied to ARM model or ASM model?
I got different results when I run Get-AzureRmSubscription (ARM based) and Get-AzureSubscription (ASM based). I thought I should get similar result.
I have AzureRM (6.4.0) and Azure (5.3.1). I already run Add-AzureAccount (ASM), Add-AzureRmAccount (ARM), Connect-AzureRmAccount (ARM).
I am not able to find any documentation. I found this thread https://social.msdn.microsoft.com/Forums/en-US/a5a9d94e-882d-4443-bd18-fa55d95aed41/getazuresubscription-vs-getazurermsubscription?forum=azurescripting but it said a subscription is not inherently ASM or ARM.
Note: Azure RM PowerShell models are tied to ARM models.
The Azure classic deployment model is not supported by this version of Azure PowerShell. For support for classic deployments, follow the instructions in Install the Azure PowerShell Service Management module.
You may use the following steps to select the right subscription.
For ASM model:
Sign in to your account for the classic model.
Add-AzureAccount
Get the available subscriptions by using the following command:
Get-AzureSubscription | Sort SubscriptionName | Select SubscriptionName
Set your Azure subscription for the current session. This example sets the default subscription to My Azure Subscription. Replace the example subscription name with your own.
Select-AzureSubscription –SubscriptionName "My Azure Subscription"
For ARM model:
Sign in to your account for the ARM model.
Add-AzureRmAccount
To change the current subscription, use the following steps:
Get-AzureRmSubscription
It will List all your subscriptions.
Select-AzureRmSubscription -SubscriptionId xxxxx-xxx-xxx-xxxx
The SubscriptionID can be found in the output of the Get-AzureRmSubscription. You can also use the SubscriptionName.
(Get-AzureRmContext).Subscription
Confirm that you have selected the right subscription.
AFAIK, if the subscription was created after a certain time, it is quite possible that the Get-AzureSubscription i.e. service manager api is not available to that subscription.
This would ensure that all Resources are created with the new resource manager api only. The ARM powershell is just for ARM models, and the ASM powershell is just for ASM models.
For more details about ARM and ASM , you could refer to the articles, 1 and 2.
Related
I need to select my Azure Subscription in Azure PowerShell.
I copy/paste the Subscription ID (to ensure no typos) from the Azure Management Portal, it's a hex-string:
When I run:
Select-AzureSubscription -SubscriptionId '0300...'
I get an error message:
Select-AzureSubscription : The subscription id 0300... doesn't exist.
I know my subscription ID is correctly copied from the settings in Azure Management Portal, I even did a BeyondCompare to make sure.
I'm wondering about security... am I missing something? Do I need to somehow provide my Azure credentials? It wouldn't make sense to just allow anyone to select any Azure subscription, unless the Subscription ID is supposed to be super-secret, like an SSN.
You need to log on to your Azure account first:
To start working with the Azure Service Management cmdlets, first log
on to your Azure account. To log on to your account, run the following
command:
Add-AzureAccount
After logging into Azure, Azure PowerShell creates a context for the
given session. That context contains the Azure PowerShell environment,
account, tenant, and subscription that will be used for all cmdlets
within that session. Now you are ready to use the modules below.
Source: https://learn.microsoft.com/en-us/powershell/azure/install-azure-ps?view=azuresmps-3.7.0
I'm trying to retrieve a complete list of VMs through PowerShell, but I'm having trouble pulling Classic VMs, and I'm having trouble understanding the distinction between RM and regular cmdlets, particularly when it comes to subscriptions.
Get-AzureRMSubscription correctly returns a complete list of the subscriptions my Azure account has access to. Get-AzureSubscription returns nothing. This means that I can correctly pull all of the new style VMs from any one subscription using Get-AzureRMVM, but since I can't find a 'classic' style subscription, I can't pull any of my existing classic VMs as I can't define which subscription to look in.
I can successfully view all VMs in all Subscriptions through the portal, but not through Powershell for whatever reason. I'm all out of ideas, is there something I'm missing?
Get-AzureRMSubscription Get-AzureSubscription Get-AzureRMVM are resource mode cmdlet, your VMs are classic mode VM, you should use classic cmdlets. Just use the following cmdlets.
#login your classic account
Add-AzureAccount
# Enumerates all configured subscriptions on your local machine.
Get-AzureSubscription
# Select the subscription to use
Select-AzureSubscription -SubscriptionName "mysubscription"
#get classic VM
Get-AzureVM
Classic VM's were the norm when Azure was used using manage.windowsazure.com where, each virtual machine had a cloud service attached to it by default and resources such as Virtual Networks and Firewalls (ACL) were static to each resource.
Azure Resource Manager (ARM) based deployments gives you the power of having flexible deployment models (e.g. one firewall/NSG for x number of VM's). A detailed study can be found on the below link:
Azure Resource Manager based deployments explained
For your question you can use the below Cmdlets to get all classic virtual machines.
#login your classic (work AD / Personal) account using the pop-up
Add-AzureAccount
# Get All subscriptions under the non-rm account. DO NOT USE Get-AzureRMSubscription for any classic resources
Get-AzureSubscription
# Select the subscription to use using the Subscription name or ID (if all your subscription names say pay-as-you-go for e.g. you may want to use your subscription ID)
Select-AzureSubscription -SubscriptionName "enter-your-subscription-name" OR -SubscriptionId "alternatively-use-subscription-id"
#List all the VM's in a variable for further use (if needed, else direct display)
$vmList = Get-AzureVM
#Output the Virtual Machines on the subscription
Write-Output ($vmList)
Done !
I am able to login successfully with the Login-AzureRmAccount. Also I am able to see my subscription in the return value of Login-AzureRmAccount. But after login, if I type Get-AzureSubscription it return empty.
Find the below screenshot
Well, you need to use Get-AzureRmSubscription (RM), since you are using the cmdlet for ASM mode, not ARM.
There are 2 deployment modes in Azure, ASM (old) and ARM (new one).
Expanding on the other answers.
In Azure there is two deployment models. Azure Service Management (ASM) and Azure Resource Manager (ARM).
To interact with anything in ASM, you utilise the Azure Module, For Example:
Add-AzureAccount Logs into ASM
Select-AzureSubscription Selects the Subscription you allocate to work within
Get-AzureSubscriptions Shows you all subscriptions
To interact with anything in ARM, you utilise the AzureRM Modules, For Example:
Add-AzureRmAccount Logs into ARM
Select-AzureRmSubscription Selects the ARM Subscription you allocate to work within
Login-AzureRmAccount Logs into ARM Also
ARM PowerShell Overview
ASM PowerShell Overview
I am trying to login to Azure AD using PowerShell with a co-administrator account. I use Connect-MsolService and I get in but I can't see any subscriptions when I use Get-AzureSubscription. At the same time, I can login in the portal (both old and new) using that account and I see it there. The issue is I need to do some things that both portals do not let me do.
Is there an issue if I created the subscription using a Microsoft account on outlook.com? Am I missing something?
Just to add to the discussion, if you're not a direct owner of the subscriptions (but have an admin role for the whole or part of the Azure infrastructure) you can use the following cmdlets to get all subscriptions and switch between them:
Get-AzureRmSubscription
Select-AzureRmSubscription -SubscriptionName "subscription_name"
https://learn.microsoft.com/en-us/powershell/module/azurerm.profile/get-azurermsubscription?view=azurermps-5.0.0
This lists the available subscriptions for co-admins and contributors and can be used in Azure resource management scripts if you do not directly own the subscription but have sufficient privileges to access the resources.
Do you get a sign in dialgoue when you run Add-AzureAccount from powershell?
Can you then Get-AzureSubscription after that?
These guides might help in ensuring all the basics work:
https://redmondmag.com/articles/2016/01/25/connect-to-microsoft-azure-with-powershell.aspx
https://azure.microsoft.com/en-gb/documentation/articles/powershell-install-configure/
Update:
What are you trying to do after?
If you want to switch subscriptions, does the following work?:
Switch-AzureMode –Name AzureResourceManager
Get-AzureSubscription
Ref:
https://msdn.microsoft.com/en-us/library/azure/dn931949.aspx
I am trying to run a task on TFS which requires AD set up. I managed to set up all connections, but for some reason Subscription on TFS is not selected.
I am not sure to what account do I have to log in, to set default subscription. -Default parameter is deprecated btw.
Task add-on I am trying to use is downloadable here:
https://marketplace.visualstudio.com/items?itemName=rbengtsson.appservices-start-stop&showReviewDialog=true
TFS build error:
I tried to set up via power-shell:
I have tested the Azure AppServices Stop task on my side, and found this task works perfectly with Azure Classic Connection Type, but while used Azure Resource Manager Connection Type, I got the same error message as you.
According to the source code of Azure AppServices Stop task on GitHub, this task actually uses Azure Power Shell below to stop the service:
$website = Get-AzureWebsite -Name $WebAppName
Stop-AzureWebsite -Name $WebAppName
It seems Stop-AzureWebsite only works with Azure Classic, as we can't find it in Using Azure PowerShell with Azure Resource Manager.
In conclusion, if you want to use Azure AppServices Stop task, you need to choose Azure Classic Connection Type:
Using the latest version of AzureRM Powershell you now can use Azure Resource Manager connection type and use commands like:
Start-AzureRmWebApp
Stop-AzureRmWebApp