如何使用 powerShell 在 Azure key-vault 机密上存储 json 文件内容(密钥)?

How to store json file content(Secret Key) on Azure key-vault secrets, using powerShell?

json 文件可能有一个或多个数据块,如下所示。

[
    {
        "ApplicationName":  "123456.Abcv.WFcvsdfa",
        "SecretKey":  "NDRkNDJjOTAtZjBhYi00NctYjkwYTNlMjNmZTQy"
    }
]

[
    {
        "ApplicationName":  "753456.Abcv.WFcvsdfa",
        "SecretKey":  "NDRkNDJjOTAtZjBhYi00NctYjkwYTNlMjNmZTQy"
    },
    {
        "ApplicationName":  "9045647.GQERDF.GDEAGJWSasdf",
        "SecretKey":  "OTlmMmMxYjgtZjEzMS00MTkwLWI1NDQtYjI2MT"
    }
    {
        "ApplicationName":  "1523456.Abcv.WFcvsdfa",
        "SecretKey":  "NDRkNDJjOTAtZjBhYi00NctYjkwYTNlMjNmZTQy"
    },
    {
        "ApplicationName":  "3645647.GQERDF.GDEAGJWSasdf",
        "SecretKey":  "OTlmMmMxYjgtZjEzMS00MTkwLWI1NDQtYjI2MT"
    }
    {
        "ApplicationName":  "5423456.Abcv.WFcvsdfa",
        "SecretKey":  "NDRkNDJjOTAtZjBhYi00NctYjkwYTNlMjNmZTQy"
    },
    {
        "ApplicationName":  "6445647.GQERDF.GDEAGJWSasdf",
        "SecretKey":  "OTlmMmMxYjgtZjEzMS00MTkwLWI1NDQtYjI2MT"
    }
]

机密名称应为 ApplicationName。必须从应用程序名称中删除圆点。

谢谢,非常感谢你的帮助

这里我得到了这个post的解决方案,希望以后对其他人有帮助。

$VaultName = "test900066"
$hashtable = Get-Content 'out.json' | ConvertFrom-Json 

foreach ($h in $hashtable.GetEnumerator()) {
    
    $SecureString = ConvertTo-SecureString $h.SecretKey -AsPlainText -Force
    $ApplicationName = $h.ApplicationName -Replace '\.',''
    # Write-Host "$($ApplicationName) : $SecureString"
    Set-AzKeyVaultSecret -VaultName $VaultName -Name $ApplicationName -SecretValue $SecureString
}