As you start doing anything advanced in Microsoft Azure you will need to use Microsoft’s PowerShell often. There are multiple ways you can login to Azure using PowerShell. In post I am only showing the new ways with resource management not the classic service management.
Option 1 : Log in to Azure with Login-AzureRmAccount
PS C:\> Login-AzureRmAccount
When I run Login-AzureRmAccount, I see a dialog like the one below, asking for credentials:
With successful login you can see the output
With this method you always have to enter your credentials before you start working with Azure cmdlets. This may be inconvenient if you work with multiple subscriptions.
Option 2 : Saving credentials with Save-AzureRmProfile
Make sure you are log in first
PS C:\> Login-AzureRmAccount
PS C:\> Save-AzureRmProfile -Path “C:\Folder\AzureProfile.JSON”
This will create the file AzureProfile.json, which contains all the login information for your Azure account.
Important Note: This file is a plain-text JSON file. If an unauthorized person gains access to this file, it would compromise your Azure account, and this person could use Azure resources on your costs.
Now you can login with this profile by just selecting the profile.
PS C:\> Select-AzureRmProfile -Path “C:\Folder\AzureProfile.JSON”
Since profile is tied up with subscription, you can work with only one profile at a time. If you want to work with multiple subscriptions simultaneously, you will need to save and select another profile.
Option 3 : Using PowerShell Profile
You can choose this while balancing security against convenience. Add following two lines of code into you PowerShell Profile.
$azCred = Get-Credential -UserName AzureAccount@YourDomain.onmicrosoft.com -message "Enter Password For AzureAdmin" Login-AzureRmAccount -Credential $azCred
It will prompt only for password for your azure account and login.
Now start using Azure commands.
That’s it.
You must be logged in to post a comment.