I'm trying to write a simple script to retrieve a key value from Azure Storage account. Below is the code:
az login
az account set --subscription 1111-222-3333-444-55555555
$azure_blob_login = "teststorage123"
$azure_blob_access_key = az storage account keys list --account-name $azure_blob_login
Write-Output $azure_blob_access_key
Write-Output $azure_blob_access_key[0]
The output from the first write-output is:
[
{
"creationTime": "2022-02-23T06:45:00.085500 00:00",
"keyName": "key1",
"permissions": "FULL",
"value": "11111111111111111111111111111111111111111111111"
},
{
"creationTime": "2022-02-23T06:45:00.085500 00:00",
"keyName": "key2",
"permissions": "FULL",
"value": "22222222222222222222222222222222222222222222"
}
]
However the output from the second write-output where I am trying to index to just get the first value in the array is just: [
Anyone know how I can return the value from this az command and only get the first "value" entry from the first entry in the array?
Thanks,
CodePudding user response:
The default output from Az cli is JSON.
If you want to create an array of properties you would have to convert the az cli output to a psobject
$keys = $azure_blob_access_key | ConvertFrom-Json
$keys[0]