Powershell Azure:构建模板:如何提取defaultStorageAccount
我正在尝试从默认存储帐户中存储的vhd映像在Azure DevTestLab中创建自定义映像 我开始修改ARM模板的文件,以便从vhd创建自定义映像 我已经创建了DevTest实验室,可以运行以下Powershell命令获取其数据:Powershell Azure:构建模板:如何提取defaultStorageAccount,powershell,azure,build-templates,Powershell,Azure,Build Templates,我正在尝试从默认存储帐户中存储的vhd映像在Azure DevTestLab中创建自定义映像 我开始修改ARM模板的文件,以便从vhd创建自定义映像 我已经创建了DevTest实验室,可以运行以下Powershell命令获取其数据: PS C:\git> $rid = Get-AzureRmResource -ResourceGroupName jgTl9-rg -ResourceType Microsoft.DevTestLab/labs -ResourceName jgTl9 -Api
PS C:\git> $rid = Get-AzureRmResource -ResourceGroupName jgTl9-rg -ResourceType Microsoft.DevTestLab/labs -ResourceName jgTl9 -ApiVersion 2016-05-15
这会产生大量信息。如果要提取默认存储帐户名,请执行以下操作:
PS C:\git> $rid.properties.defaultStorageAccount
所以我知道有可能得到它。现在,我修改了Azure构建模板(JSON文件)的变量部分,如下所示:
"variables": {
"resourceName": "[concat(variables('existingLabName'), '/', variables('imageName'))]",
"resourceType": "Microsoft.DevTestLab/labs/customimages",
"existingLabName": "[replace(resourceGroup().name,'-rg','')]",
"storageAccountID": "/subscriptions/xxxxxxxxxxxx/resourceGroups/jgTl9-rg/providers/Microsoft.Storage/storageAccounts/djgtl91795",
"saidFrags": "[skip(split(variables('storageAccountID'), '/' ), add(length(split(variables('storageAccountID'), '/' )),-1) ) ]",
"storageAccountSuffix": "[take(variables('saidFrags'),1)[0]]",
"existingVhdUri": "[concat('https://',variables('storageAccountSuffix'),'.blob.core.windows.net/uploads/',parameters('imageFileName'))]",
"imageName": "JaysImage"
},
当我使用azuredeploy.json和azuredeploy.parameters.json调用新的AzureRmResourceGroupDeployment命令时,这段代码实际上可以工作
但是,我想从环境中提取defaultStorageAccount,而不是硬编码storageAccountID变量。我试过这样的方法:
"storageAccountID": "[string( resourceId(resourceGroup().name,'MicrosoftDevTestLab/labs','jgTl9').properties.defaultStorageAccount ))",
我尝试了一些变化,但没有任何效果。提取与我硬编码的storageAccountID相同的信息需要使用什么语法
(我在中找不到任何内容)。以下表达式有几个问题
"storageAccountID": "[string( resourceId(resourceGroup().name,'MicrosoftDevTestLab/labs','jgTl9').properties.defaultStorageAccount ))",
)
李>
MicrosoftDevTestlab/labs
应该是Microsoft.DevTestlab/labs
resourceId
时,它不会提供整个对象。因此,当您执行properties.defaultStorageAccount
操作时,它将不起作用。因为它只提供dev测试实验室的字符串,没有其他内容,而且defaultStorageAccount
的字符串上没有属性李>
现在您需要的是如下所示的reference
函数
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"vDefaultStorageAccount": "[string(resourceId('yourResourceGroupName','Microsoft.DevTestLab/labs','yourTestLabName'))]"
},
"resources": [],
"outputs": {
"defaultStorageAccount":{
"value": "[reference(variables('vDefaultStorageAccount'),'2016-05-15').defaultStorageAccount]",
"type":"string"
}
}
}
在变量中,vDefaultStorageAccount
获取DevTestLab
的ID,然后使用reference
函数获取对象。然后您可以执行
以获取属性。例如,您不需要执行properties.defaultStorageAccount