问题描述
我已经安装了PowerShell 6.1.3版本,并且我想使用以下Azure PowerShell命令建立与Azure帐户的连接:
I have installed the PowerShell 6.1.3 version andI want to get a connection to the Azure account using the following Azure PowerShell command:
Connect-AzAccount -Tenant <tenantId> -Subscription <subId>
输入此命令后,我将获得带有URL和一些代码的警告.然后,我必须转到URL并在此处输入代码.之后,我获得了与Azure帐户的连接.
After entering this command I get the warning with the url and some code.Then I have to go to the URL and enter the code there. After that, I get a connection to the Azure account.
有什么方法可以避免此确认?
我还尝试使用以下命令进行操作:
I've also tried to do it using the following command:
az login -u <username> -p <password>
此命令仅返回一些帐户信息(subscriptionId,tenantId等),但不会安装与此帐户的连接.
This command only returns some account information(subscriptionId, tenantId etc) but it doesn't install a connection to this account.
推荐答案
1.要使用用户帐户登录,请尝试以下命令,请确保您的帐户未启用MFA(多重身份验证)./p>
1.To login with the user account, try the command as below, make sure your account doesn't enable the MFA(Multi-Factor Authentication).
$User = "xxx@xxxx.onmicrosoft.com"
$PWord = ConvertTo-SecureString -String "<Password>" -AsPlainText -Force
$tenant = "<tenant id>"
$subscription = "<subscription id>"
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User,$PWord
Connect-AzAccount -Credential $Credential -Tenant $tenant -Subscription $subscription
2.您还可以使用服务主体登录,请使用以下命令.
2.You can also use a service principal to login, use the command as below.
$azureAplicationId ="Azure AD Application Id"
$azureTenantId= "Your Tenant Id"
$azurePassword = ConvertTo-SecureString "strong password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
看到类似的问题,我在此处回答了使用旧的AzureRM
模块,对于Az
,只需更改最后一行.
See a similar issue I answered here, it use the old AzureRM
module, for Az
, just change the last line.
如果您不熟悉服务主体,另请参见:方法:使用门户来创建可以访问资源的Azure AD应用程序和服务主体,应用程序ID和身份验证密钥是Azure AD Application Id
和strong password
.
If you are not familiar with service principal, Also see : How to: Use the portal to create an Azure AD application and service principal that can access resources, the application id and authentication key are the Azure AD Application Id
and strong password
you need.
这篇关于Connect-AzAccount-如何避免azure设备身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!