Azure CLI 无法识别参数

时间:2021-04-22 16:38:21

标签: azure powershell azure-devops azure-cli

尝试在 Powershell 脚本中运行以下命令:

    $statblob = az storage blob exists --container-name "dev-tfstate" --name "mh/fw-mh-$varenv-__region__-__suffix__.tfstate" --account-key $blobkey --account-name "fwdevstate767442" --subscription $mgtsub | ConvertFrom-Json

我收到以下错误:

ERROR: the following arguments are required: --container-name/-c, --name/-n

我在使用 --account-name 参数时遇到了同样的错误,直到我删除了该变量并将名称硬编码到脚本中。值是有效的,只是似乎没有认识到参数在那里?

编辑:我将参数更改为 -c 和 -n 的别名,现在我在帐户名参数上遇到错误。

ERROR: unrecognized arguments: account-name fwdevstate767442

2 个答案:

答案 0 :(得分:1)

终于找到了解决办法。与由于某种原因没有正确解释的变量有关。在函数中将它们设置为环境变量解决了这个问题,之后脚本运行良好。

答案 1 :(得分:0)

我们在没有任何错误的情况下尝试了此命令,问题可能在于您在 Powershell 脚本中运行了此 Azure CLI 命令。

有两种解决方案:

  1. 使用 Powershell 命令检查 blob 是否存在。
<块引用>

A solution 是在 try/catch 中包装对 Get-AzureStorageBlob 的调用并捕获 ResourceNotFoundException 以确定该 blob 不存在。

  1. 将整个脚本更改为 Azure CLI 命令。
相关问题