Persist/Save Azure login credentials in a PowerShell session

When working with Azure its very common to open multiple PowerShell windows in order to execute multiple PS scripts in parallel to get the work done faster. One of the repetitive task we have to do is to login to Azure portal in each new PS window.

In order to avoid the above mentioned hassle we can save the Azure login credentials to a json file and re-use it across multiple PS sessions/windows. The save credentials are valid for 12 hours.

#Login to Azure subscription

#If you have multiple subscriptions associated with the login, view all subscriptions

#Select the subscription for the current session
Select-AzureRmSubscription -SubscriptionId <guid of Azure subscription>

#Save the credentials to a json file
Save-AzureRmProfile -Path C:\Projects\AzureLogin.json

Once the credentials are saved using the above procedure, whenever you open a new PS window you can re-user the credentials as below;

#select the persisted Azure credentials from the json file (in new PowerShell window)
Select-AzureRmProfile -Path C:\Projects\AzureLogin.json