1
votes

I tried to use Login-AzureRmAccount and Add-AzureRmAccount to login to my Azure Accounts. I have two of them, it was easy to add both of them via Add-AzureAccount and manage the active and default one using Select-Azuresubscription.

With the RM cmdlets every time I do Add-AzureRmAccount it overrides the previous authenticated one. This makes it hard for me to switch between a private and a company azure account.

Are there any solutions for that ? I am using the PowerShell Gallery to update the Azure and AzureRM Modules and using the latest ones.

2

2 Answers

1
votes

The official way is to do something like this

$profile1 = Login-AzureRmAccount 
$profile2 = Login-AzureRmAccount

Select-AzureRmProfile -Profile $profile2

You can then save the profiles to disk using

Save-AzureRmProfile -Profile $profile1 -Path e:\ps\profile1.json 

You can then load with

Select-AzureRmProfile -Path e:\ps\profile1.json 

My personal approach though was to create a module that gave a cmdlet with profile1,profile2 etc as parameters. It would then download and decrypt credentials and feed them into Add-AzureRMAccount (this way I can use the same credential file from assorted locations)

1
votes

Use Login-AzureRMAccout to login two accounts respectively. Then use Get-AzureRmSubscription to check the subscription info and note down the two TenantIds.

To switch between a private and a company azure account, you can specify the TenantId parameter using

 $loadersubscription = Get-AzureRmSubscription -SubscriptionName $YourSubscriptionName -TenantId $YourAssociatedSubscriptionTenantId