我創建了 Azure AD 安全原則。我已經從秘密中創建了一個安全字串,所以我不必將它以純文本形式保存在某個地方。
現在,在我使用 az cli 的部署腳本中,我想使用這些憑據登錄 Azure,但一直提示我輸入密碼。我想避免提示,只提供客戶端密碼或加密密碼作為引數。
這是代碼:
#Load Environment variables
$localenv = (Get-Content './environmentVars.json' | Out-String | ConvertFrom-Json)
$AzCred = Get-Credential -UserName $localenv .APP_ID
az login --service-principal -u $AzCred.UserName -p $localenv.APP_ID_CLIENT_SECRET --tenant $localenv.AZ_TENANT_ID
當我運行腳本時,它會這樣做:
PS C:\Users\me> .\deploy-resources.ps1
PowerShell credential request
Enter your credentials.
Password for user [GUID for Security Principle]:
有沒有辦法可以將它傳遞給 powershell 腳本?
至于秘密的加密版本,這就是我創建它的方式:
$Secure = Read-Host -AsSecureString (supply the secret)
$Encrypted = ConvertFrom-SecureString -SecureString $Secure
然后我從客戶端密碼中創建了一個安全字串:
$Secure2 = ConvertTo-SecureString -String $Encrypted
如果有辦法這樣做,我想將 $Secure2 的內容保存在我的 json 檔案中并使用它而不是實際的秘密值。
任何提示將不勝感激。
uj5u.com熱心網友回復:
我們已嘗試使用您正在使用的相同 PowerShell 腳本,但遇到了與提示密碼相同的問題。

我們對您的腳本進行了如下更改,并且無需提示輸入密碼即可登錄。
$localenv = (Get-Content -Path "C:\Users\v-aghose\Desktop\environmentVars.json.txt" | Out-String | ConvertFrom-Json)
#$AzCred = Get-Credential -UserName $localenv.APP_ID
az login --service-principal -u $localenv.APP_ID -p $localenv.APP_ID_CLIENT_SECRET --tenant $localenv.AZ_TENANT_ID --allow-no-subscriptions
輸出:-

如果我們將客戶端密碼作為加密的安全字串傳遞,則該字串對 login 不起作用。為了讓它登錄,我們必須解碼加密的字串。所以會浪費加密客戶端密碼。
For more information about decrypted the encrypted secure strings please refer this SO THREAD .
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/444151.html
標籤:天蓝色 电源外壳 天蓝色的PowerShell 天蓝色的cli 天蓝色证书
