Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Login without prompt?

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.

like image 211
H Bala Avatar asked May 16 '16 08:05

H Bala


People also ask

How do I connect my AzureRmAccount?

To sign in interactively, use the Connect-AzureRmAccount cmdlet. When run, this cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. This authentication lasts for the current PowerShell session.

What is connect-AzAccount?

Description. The Connect-AzAccount cmdlet connects to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules. You can use this authenticated account only with Azure Resource Manager requests.

How do I run AZ login in PowerShell?

To sign in interactively, use the Connect-AzAccount cmdlet. This cmdlet presents an interactive browser based login prompt by default. Use the Get-AzContext cmdlet to store your tenant ID in a variable to be used in the next two sections of this article.

How do I connect to Azure from PowerShell?

Sign in to Azure Sign in interactively with the Connect-AzAccount cmdlet. Skip this step if you use Cloud Shell. Your Azure Cloud Shell session is already authenticated for the environment, subscription, and tenant that launched the Cloud Shell session. Beginning with Az PowerShell module version 5.0.


1 Answers

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 
like image 135
Jack Zeng Avatar answered Sep 19 '22 15:09

Jack Zeng