我正在使用模板和参数文件部署虚拟机。我想覆盖参数文件 virtualMachineName,这样我就可以动态命名每个虚拟机,而不需要 10 个不同的参数文件。这样做的正确语法是什么?
目前我有:
New-AzureRmResourceGroupDeployment -ResourceGroupName "myRSG" -TemplateFile $server1TmpFile -TemplateParameterFile $serverParamFile -virtualMachineName "AS1FTW12" -networkInterfaceName "AS1FTW12NIC" -networkSecurityGroupName "MyNSGName"
这会产生一个错误: New-AzureRmResourceGroupDeployment:找不到与参数名称“virtualMachineName”匹配的参数
我正在使用 PowerShell Tools for Visual Studio 2017 编写脚本。根据 Get-Module AzureRM,我安装的 PowerShell AzureRM 版本是 5.1.1。
最佳答案
这适用于 AzureRM 5.1.1,您可以使用以下设置进行测试:
模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"paramTest": {
"type": "string"
}
},
"resources": [],
"outputs": {
"result": {
"type": "string",
"value": "[parameters('paramTest')]"
}
}
}
参数:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"paramTest": {
"value": "GEN-UNIQUE"
}
}
}
Powershell:
New-AzureRmResourceGroupDeployment -ResourceGroupName rg -TemplateFile template.json -TemplateParameterFile param.json -paramTest somevalue
输出值等于从 powershell 传递的值
您的错误表明参数名称错误,请仔细检查
关于powershell - 覆盖脚本中的模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48302111/