Get and Regenerate Azure AI Services Access Key using PowerShell

This blog post will demonstrate how to retrieve and regenerate the access key for Azure AI Services using PowerShell.

This is particularly useful when you need to rotate your keys for security reasons or believe your existing key might have been compromised.

We create two variables: the resource group and the Cognitive Services account we want to manage.

$resourceGroupName = "AzureAIServices"
$accountName = "ntwaiservices"

We can retrieve the details of this Cognitive Services account using the `Get-AzCognitiveServicesAccount` cmdlet.

get-AzCognitiveServicesAccount -ResourceGroupName $resourceGroupName | select *

Getting the Access Key

We can retrieve the access key using the `Get-AzCognitiveServicesAccountKey` cmdlet.

$accessKey = (Get-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroupName -Name $accountName).Key1

We can then output the access key to the console.

Write-Host "Access Key: $accessKey"

Regenerating the Access Key

Finally, we can regenerate the access key using the `New-AzCognitiveServicesAccountKey` cmdlet.

Note: This cmdlet will invalidate the old key, and any applications using the old key will stop working until they are updated to use the new key.

New-AzCognitiveServicesAccountKey -ResourceGroupName $resourceGroupName -Name $accountName -KeyName Key


Posted

in

, ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.