Login-AzureRmAccount from VS Code terminal

2019-04-21 21:11发布

问题:

When I try to login to Azure RM from VS Code terminal it just hangs. No prompt with login / password is shown.

Is there any way to get logged in from that terminal? Otherwise running / debugging Azure PS scripts becomes more complicated than it should be :)

回答1:

The login window pops-up in the background... if you minimize all your windows you'll eventually find it.



回答2:

You need to wait for a moment, then you could see the login page.

According to your description, I suggest you could select Non-interactive login. You could create a service principal that can access resource. Please refer to this link:Use portal to create an Azure Active Directory application and service principal that can access resources. You will get clientid and client secret. You could use the following code to login your Azure account.

$subscriptionId=""
$tenantid=""
$clientid=""
$password=""
$userPassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$userCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $clientid, $userPassword
Login-AzureRmAccount -TenantId $tenantid -ServicePrincipal -SubscriptionId $subscriptionId -Credential $userCredential