azure - 无法使用 powershell 脚本中的 az cli 通过参数部署 Azure ARM

标签 azure powershell azure-resource-manager

尝试使用 PS 脚本中的参数进行简单部署:

$prefix = "xxx"
$location = "switzerlandnorth"
az deployment group create `
    --name  $timestamp  `
    --resource-group $resourceGroupName `
    --mode incremental `
    --verbose `
    --template-file .\src\ops\scripts\arm.json `
    --parameters "{ `"location`": { `"value`": `"$location`" },`"projectPrefix`": { `"value`": `"$prefix`" } }"


响应有错误:

Unable to parse parameter: { location: { value: switzerlandnorth }, projectPrefix: { value: xxx } }

从 PS1 脚本运行

最佳答案

正如我们在错误中看到的,它无法解析参数。将参数传递给 az Deployment Group create 命令的正确方法是:

 az deployment group create `
 --name  $timestamp  `
 --resource-group $resourceGroupName `
 --mode "incremental" `
 --verbose `
 --template-file ".\src\ops\scripts\arm.json" `
 --parameters '{ \"location\": { \"value\": \"switzerlandnorth\" },\"projectPrefix\": { \"value\": \"xxx\" } }' 

更新:

如果您想在参数中传递 PowerShell 变量,您可以执行如下操作 -

 $location = "switzerlandnorth"
 $projectPrefix = "xxx"
 $params = '{ \"location\": { \"value\": \" ' + $location + '\" },\"projectPrefix\": { \"value\": \"' + $projectprefix + '\" } }' 
 az deployment group create `
 --name  $timestamp  `
 --resource-group $resourceGroupName `
 --mode "incremental" `
 --verbose `
 --template-file ".\src\ops\scripts\arm.json" `
 --parameters $params

希望这有帮助!

关于azure - 无法使用 powershell 脚本中的 az cli 通过参数部署 Azure ARM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62674984/

相关文章:

Azure Bicep - 依赖模块的计时

powershell - 是否可以编写 Azure 应用服务身份验证配置脚本?

azure - 如何在 Windows Azure 网站上存储文件?

c# - 以编程方式使用 Sandbox 的 azure CreateNotificationHub

node.js - Azure 云服务和持久配置设置

regex - Powershell获取文件中大括号之间的所有字符串

powershell - 创建带有框字符的控制台菜单

powershell - 如何从事件日志中仅检索事件消息?

Azure ARM 模板 vnet 对不同订阅进行对等

azure - 无法在存储模拟器上创建 azure blob 容器