TakeCourage
TakeCourage

Reputation: 69

Azure CLI not recognizing arguments

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

Upvotes: 1

Views: 7556

Answers (2)

TakeCourage
TakeCourage

Reputation: 69

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.

Upvotes: 2

Doris Lv
Doris Lv

Reputation: 3398

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.

Upvotes: 1

Related Questions