0

Trying to run the following command in a Powershell script:

    $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

And I get the following error:

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

I was getting the same error with the --account-name argument until I removed the variable and hard coded the name into the script instead. The values are valid, it just doesn't seem to recognize that the arguments are there?

Edit: I changed the arguments to their aliases of -c and -n, and now I get the error on the account-name argument.

ERROR: unrecognized arguments: account-name fwdevstate767442

Yash Gupta
  • 1,807
  • 15
  • 21
TakeCourage
  • 21
  • 1
  • 5

2 Answers2

1

Finally found a fix. Had to do with variables not being interpreted right for some reason. Setting them as environment variables within the function solved it and the script ran fine afterward.

TakeCourage
  • 21
  • 1
  • 5
0

We tried this command without any errors, the problem might be that you run this Azure CLI command inside your Powershell script.

There are two solutions:

  1. Using Powershell command to check if the blob exists or not.

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

  1. Change your whole scripts to Azure CLI command.
Doris Lv
  • 3,083
  • 1
  • 5
  • 14