我面臨一個奇怪的問題,我不知道為什么它不起作用。我查看了所有檔案并嘗試了不同的解決方案,但什么也沒有。
我正在嘗試在 powershelgl 中撰寫一個帶有 2 個值的簡單命令:
- 秘密名稱
- 秘密價值
我想value在 powershell 執行期間確保安全,并在腳本完成時查看這些引數存盤在 azure KeyVault -> Secrets 中。
我已經設定了這個代碼:
$SecretName = Read-Host "Enter Secret Name"
$password = Read-Host "Enter password" -AsSecureString
$password = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$password = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($password)
Set-AzKeyVaultSecret -VaultName "keyvaultname" -Name $SecretName -SecretValue $password
但這給了我以下錯誤:
Cannot bind parameter 'SecretValue'. Cannot convert the "asdlkjiou" value of type "System.String" to type "System.Security.SecureString".
注意:我正在將密碼轉換回,因為如果我不這樣做,代碼會運行,但 KeyVault 中的值顯示如下 System.Security.SecureString
我在這里迷路了,很長時間沒有使用 Windows PowerShell,我找到的任何解決方案或檔案都沒有幫助我解決這個問題。
請,如果有人能指導我如何實作這一點,我將不勝感激。
如果您需要更多資訊,請隨時問我
uj5u.com熱心網友回復:
您不需要通過InteropServices呼叫執行這些轉換。只需使用這三行。該password變數已經是正確的型別,因為你讀它的-AsSecureString。
$SecretName = Read-Host "Enter Secret Name"
$password = Read-Host "Enter password" -AsSecureString
Set-AzKeyVaultSecret -VaultName 'keyvaultname' -Name $SecretName -SecretValue $password
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/358611.html
標籤:天蓝色 电源外壳 运维 天蓝色资源管理器 azure-keyvault
上一篇:如何使用內連接和聚合函式更新列?
