我尝试使用以下命令来获得更快的登录体验,但每次我都找到登录弹出窗口。我甚至最初尝试使用证书,但由于这不能证明有效,尝试使用租户ID。关于如何无缝和快速登录而不是交互式的任何帮助或建议。
Login-AzureRmAccount -SubscriptionId 1238154XXXXfd-1c4121796e58 -TenantId 754XXXXXXXXXXX5d10d8XXX
Add-AzureRmAccount -Tenant "754XXXXXXXXXXX5d10d8XXX" -SubscriptionId "1238154XXXXfd-1c4121796e58"
Login-AzureRmAccount -TenantId 754XXXXXXXXXXX5d10d8XXX
或者,是否必须始终通过交互式登录提示。请求指针,并提前感谢您的考虑和时间。
答案 0 :(得分:32)
您可以使用-Credential
参数和DPAPI登录。
首先,运行以下PowerShell一次,为您的帐户存储安全密码。
Read-Host "Enter Password" -AsSecureString | ConvertTo-SecureString `
-AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Password.txt"
然后,您可以使用以下脚本登录。
# 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
另一种方法是使用服务主体。首先,您应该按照the article创建服务主体
然后,使用以下脚本登录。
$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
答案 1 :(得分:21)
可能要迟到但我发现了另一个简单的解决方案,所以在此处列出以帮助其他人:
Login-AzureRmAccount
登录azure帐户。Save-AzureRmContext -Path "E:\AzureProfile.json"
将上下文保存在Json文件中。Import-AzureRmContext -Path "E:\AzureProfile.json"
。答案 2 :(得分:5)
如果您使用的是Live ID,则无法在没有提示的情况下登录。您无法以非交互方式登录。
登录后,您可以使用Save-AzureRmProfile
保存凭据,这会将登录令牌保存到磁盘,然后您可以使用Select-AzureRmProfile
再次登录。但是该令牌确实会过期,因此您将需要再次登录。
要在不提示的情况下登录,您需要创建Azure Active Directory帐户。
然后你可以使用这样的东西
$cred = Get-Credential
Add-AzureRmAccount -Credential $cred
您还可以构建凭据对象,以便可以非交互方式使用它。
答案 3 :(得分:0)
您可以使用PowerShell ISE。
遵循以下脚本:
$password = ConvertTo-SecureString 'Password' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ('Username', $password)
Connect-AzureRmAccount -Credential $Credential -Subscription 5a4dtert8-88bc-447c-bb20-b236terteb28e4 -Tenant 0d8trtec-5229-44ca-acc8-dbterte01b993b6
您可以通过
使用Power Shell ISE自动生成Connect-AzureRmAccount
脚本
通过$ credential变量传递订阅ID和租户。