Explore Courses Blog Tutorials Interview Questions
+1 vote
in Azure by (50.2k points)

I tried the below commands in order to get a no-prompt login scenario, but every time, i am getting login popup.  
I also tried to use a certificate but didn't work too. Even when tried to use tenant ID.  
 Can someone suggest to me how to get a faster no-login prompt experience?

Login-AzureRmAccount -SubscriptionId XXXX -TenantId XXXX

Add-AzureRmAccount -Tenant "XXXX" -SubscriptionId "XXXX"

Login-AzureRmAccount -TenantId XXX

2 Answers

+1 vote
by (108k points)

There is a simple way of achieving this. You can try the below steps:

  1. Login to your Azure account with the command: Login-AzureRmAccount 
  2. Save the context in a JSON file using the command: Save-AzureRmContext -Path "E:\AzureProfile.json" 
  3. Now, you can log in without prompt using the command: Import-AzureRmContext -Path "E:\AzureProfile.json"
0 votes
by (5.8k points)

You can try using -Credential parameter, and DPAPI to login. First, run the following PowerShell once to store a secured password for your account.

Read-Host "Enter Password" -AsSecureString | ConvertTo-SecureString `

-AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Password.txt"

Want to learn Azure from basics! Here's the right video for you to learn Azure provided by Intellipaat:

And then, you can try using the following script to login.

# The azure account here must not be a Live ID.

$username = "<your Azure account>"

$SecurePassword = Get-Content "C:\Password.txt" | ConvertTo-SecureString

$cred = new-object -typename System.Management.Automation.PSCredential `

     -argumentlist $username, $SecurePassword

Login-AzureRmAccount -Credential $cred

Another way can be via using Service Principal. First, you should follow the article to create a Service Principal. And then, try using the following script to login.

$clientID = "<the client id of your AD Application>"

$key = "<the key of your AD Application>"

$SecurePassword = $key | ConvertTo-SecureString -AsPlainText -Force

$cred = new-object -typename System.Management.Automation.PSCredential `

     -argumentlist $clientID, $SecurePassword

$tenantID = "<the tenant id of your subscription>"

Add-AzureRmAccount -Credential $cred -TenantId $tenantID -ServicePrincipal

Browse Categories