H B*_*ala 28 powershell automation azure
我尝试按照命令获得更快的登录体验,但每次我找到登录弹出窗口.我甚至最初尝试使用证书,但由于这不能证明有效,尝试使用租户ID.有关如何无缝和快速登录而不是交互式的任何帮助或建议.
Login-AzureRmAccount -SubscriptionId 1238154XXXXfd-1c4121796e58 -TenantId 754XXXXXXXXXXX5d10d8XXX
Add-AzureRmAccount -Tenant "754XXXXXXXXXXX5d10d8XXX" -SubscriptionId "1238154XXXXfd-1c4121796e58"
Login-AzureRmAccount -TenantId 754XXXXXXXXXXX5d10d8XXX
Run Code Online (Sandbox Code Playgroud)
或者,我是否必须始终通过交互式登录提示.请求指针并提前感谢您的考虑和时间.
Jac*_*eng 34
您可以使用-Credential参数和DPAPI登录.
首先,运行以下PowerShell一次以存储帐户的安全密码.
Read-Host "Enter Password" -AsSecureString | ConvertTo-SecureString `
-AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Password.txt"
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用以下脚本登录.
# 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
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用服务主体.首先,您应该按照文章创建服务主体
然后,使用以下脚本登录.
$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
Run Code Online (Sandbox Code Playgroud)
Roh*_*ats 21
可能要迟到但我发现了另一个简单的解决方案,所以在这里列出来以帮助其他人:
Login-AzureRmAccount.Save-AzureRmContext -Path "E:\AzureProfile.json".Import-AzureRmContext -Path "E:\AzureProfile.json".如果您使用的是Live ID,则无法在没有提示的情况下登录.您无法以非交互方式登录.
登录后,您可以保存凭据,Save-AzureRmProfile这样可以将登录令牌保存到磁盘,然后您可以再次使用登录Select-AzureRmProfile但是该令牌确实过期,因此您需要再次登录.
要在不提示的情况下登录,您需要创建Azure Active Directory帐户.
然后你可以使用这样的东西
$cred = Get-Credential
Add-AzureRmAccount -Credential $cred
Run Code Online (Sandbox Code Playgroud)
您还可以构建凭证对象,以便可以非交互方式使用它.
| 归档时间: |
|
| 查看次数: |
36601 次 |
| 最近记录: |