powershell - 覆盖脚本中的模板参数

标签 powershell azure

我正在使用模板和参数文件部署虚拟机。我想覆盖参数文件 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/

相关文章:

azure - 无法连接到服务器: dial tcp: lookup <Server Location>: no such host

azure - 导出 CSV 显示 Azure 标记的 System.Collections.Generic.Dictionary`2[System.String,System.String]?

powershell - 使用 PowerShell 包装现有的 COM 对象

c# - 如何使用 Azure.Storage.Blobs BlobClient 检索 Blob 目录路径中的 Blob?

python - 在 Python 中创建 Azure key 保管库

windows - 是否可以使用登录的 Windows 用户凭据对 Web API 进行身份验证?

powershell - Get-Command 的行为不符合描述

powershell - 设置在 Linux 上运行的 Jenkins 来执行 PowerShell 脚本

powershell - 日期时间比较不匹配

azure - 如何在列中存储 10000 个字符串,ADF 是在接收器中的数据流中读取它还是截断它