gpt4 book ai didi

powershell - Powershell 命令可用于检索 Azure 文档数据库帐户 key 吗?

转载 作者:行者123 更新时间:2023-12-03 21:06:37 24 4
gpt4 key购买 nike

我正在使用 ARM 模板创建 DocumentDB 帐户。现在希望在创建 DocumentDB 帐户后获取帐户 key 。

我知道我们可以从 https://portal.azure.com 获取这些详细信息但我想要一个能够提供上下文的命令(例如,使用 Get-AzureStorageAccountKey 命令我们获取存储帐户的 key )

最佳答案

$ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition 

$ResourceGroupName = "ResGrp"
$Location = "South Central US"
$DocDBAccountName = "testdocdbaccount"
$TemplateFilePath = "DocumentDBJson\DocumentDB.json"
$ParameterFilePath = "DocumentDBJson\DocumentDB.param.dev.json"

$PSOutputFolder= "$ScriptPath\PowerShellOutput"

$NewParameterFilePath = $ParameterFilePath.Replace(".json",".Deploy.json")

(Get-Content "$ParameterFilePath") | Foreach-object {
$_ -replace '\$Location\$', $Location `
-replace '\$DocDBAccountName\$', $DocDBAccountName
} |Set-Content "$NewParameterFilePath" -Force

New-AzureRmResourceGroupDeployment -Name $DocDBAccountName -ResourceGroupName $ResourceGroupName -Mode Complete -Force -TemplateFile "$ScriptPath\$TemplateFilePath" -location $Location -TemplateParameterFile "$NewParameterFilePath" | ConvertTo-Json | Out-File "$PSOutputFolder\DocumentDB_$DocDBAccountName.json"

$DocDBFile = "$PSOutputFolder\DocumentDB_$DocumentDbAccount.json"
$docdbjson = Get-Content $DocDBFile | Out-String | ConvertFrom-Json
foreach ($v in $docdbjson.Outputs.keys.Value.Replace('" "','"|"').Split("|"))
{
if($v -match "primaryMasterKey")
{
$DocumentDbKey= ($v.Split(":")[-1]).Replace('"','')
}
}

--------------------- DocumentDB.Json 文件 ---------------------- -

    {
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"databaseAccountName": {
"type": "string"
},
"location": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2015-04-08",
"type": "Microsoft.DocumentDb/databaseAccounts",
"name": "[parameters('databaseAccountName')]",
"location": "[parameters('location')]",
"properties": {
"name": "[parameters('databaseAccountName')]",
"databaseAccountOfferType": "Standard"
}
}
],
"outputs": {
"Keys": {
"type": "object",
"value": "[listKeys(resourceId('Microsoft.DocumentDb/databaseAccounts', parameters('databaseAccountName')), '2015-04-08')]"
}
}
}

------------------ DocumentDB.param.dev.json 文件 -----------------

{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"databaseAccountName": {
"value": "$DocDBAccountName$"
},
"location": {
"value": "$Location$"
}
}
}

关于powershell - Powershell 命令可用于检索 Azure 文档数据库帐户 key 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33008006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com