What is the right way to get Azure Cognitive service account endpoint from Azure-CLI

346 Views Asked by At

I was using the following command

$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)

but I found out that this stopped working when I ran this on another machine with a slightly newer version of Azure-CLI.

The JSON returned by the az cognitiveservices account show command is not consistent and looks like it has changed from version to a version.

How can I reliably get this not having to worry about the version of Azure CLI on the machine that I'm running on?

Or is there a completely different way to get the endpoint value?

1

There are 1 best solutions below

2
On

With the newest version you will find endpoint in properties and since you rely on CLI version installed on the given machine you can simply modify your code to something like this:

$cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query endpoint --output tsv)

if( !$cogVisionEndpoint ) {
 $cogVisionEndpoint = (az cognitiveservices account show -n $accountName -g $resourceGroupName --query "properties.endpoint" --output tsv)
}