Azure CLI 无法识别参数

Azure CLI not recognizing arguments

正在尝试 运行 在 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

我们试过这个命令没有任何错误,问题可能是你 运行 你的 Powershell 脚本中的这个 Azure CLI 命令。

有两种解决方法:

  1. 使用 Powershell 命令检查 blob 是否存在。

is to wrap the call to Get-AzureStorageBlob in a try/catch and catch ResourceNotFoundException to determine that the blob doesn't exist.

  1. 将整个脚本更改为 Azure CLI 命令。

终于找到了解决方法。与由于某种原因没有被正确解释的变量有关。在函数中将它们设置为环境变量解决了它,然后脚本 运行 很好。