How to Login without prompt?

2019-01-21 17:02发布

I tried following commands to get a noprompt faster login experience but each time i find login popup. I even tried using the certificate initially but since that didn't prove working, attempting with tenant id. Any help or suggestion on how to have seamless and faster login instead of interactive.

Login-AzureRmAccount -SubscriptionId 1238154XXXXfd-1c4121796e58 -TenantId 754XXXXXXXXXXX5d10d8XXX

Add-AzureRmAccount -Tenant "754XXXXXXXXXXX5d10d8XXX" -SubscriptionId "1238154XXXXfd-1c4121796e58"

Login-AzureRmAccount -TenantId 754XXXXXXXXXXX5d10d8XXX

Or, is it that I have to go via interactive login prompt always. Request pointers and thank in advance for consideration and time.

3条回答
贼婆χ
2楼-- · 2019-01-21 17:31

You can use -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"

And then, you can use 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

An other way would be using Service Principal. First, you should follow the article to create a Service Principal

And then, use 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
查看更多
Animai°情兽
3楼-- · 2019-01-21 17:32

Might be late to post but I found another simple solution so listing it down here so as to help others:

  1. Login to azure account with command Login-AzureRmAccount.
  2. Save the context in Json file using command Save-AzureRmContext -Path "E:\AzureProfile.json".
  3. Now you can login without prompt using command: Import-AzureRmContext -Path "E:\AzureProfile.json".
查看更多
可以哭但决不认输i
4楼-- · 2019-01-21 17:48

If you are using a Live ID, then you can't log in without a prompt. You can't log in non-interactively.

Once you are logged in you can save your credentials with Save-AzureRmProfile this will save the login token to disk, that you can then use to login again with Select-AzureRmProfile However that token does expire, so you will need to log in again.

In order to login without being prompted at all you need to create an Azure Active Directory Account.

You can then use something like this

$cred = Get-Credential
Add-AzureRmAccount -Credential $cred

You can also build a credential object, so you can use this non-interactively.

查看更多
登录 后发表回答