azure Azure Powershell Login to Azure


Example

Classic (Service Management) mode:

Add-AzureAccount

This will authenticate you using Azure Active Directory, and PowerShell gets an access token that expires after about 12 hours. So you must repeat the authentication after 12 hours.

An alternative is to run the following cmdlet:

Get-AzurePublishSettingsFile

This opens a browser window where you can download a publish settings file. This file contains a certificate that allows PowerShell to authenticate. Then you can import your publish settings file using the following:

Import-AzurePublishSettingsFile

Remember that the publish settings file contains a certificate with effectively admin privileges in your subscription. Keep it secure or delete it after using it.

Resource manager

In Resource Manager side, we can only use Azure Active Directory authentication with the 12 hour access tokens. There are two alternative commands currently that you can use:

Login-AzureRmAccount
Add-AzureRmAccount