Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 2.26 KB

storage-common-rotate-account-keys-powershell.md

File metadata and controls

52 lines (36 loc) · 2.26 KB
title titleSuffix description services author ms.service ms.devlang ms.topic ms.date ms.author ms.custom
Rotate storage account access keys with PowerShell
Azure Storage
Create an Azure Storage account, then retrieve and rotate one of its account access keys.
storage
stevenmatthew
azure-storage
powershell
sample
12/04/2019
shaas
devx-track-azurepowershell

Rotate storage account access keys with PowerShell

This script creates an Azure Storage account, displays the new storage account's primary access key, then renews (rotates) the key.

[!INCLUDE sample-powershell-install]

[!INCLUDE quickstarts-free-trial-note]

Sample script

[!code-powershellmain]

Clean up deployment

Run the following command to remove the resource group, storage account, and all related resources.

Remove-AzResourceGroup -Name rotatekeystestrg

Script explanation

This script uses the following commands to create the storage account and retrieve and rotate one of its access keys. Each item in the table links to command-specific documentation.

Command Notes
Get-AzLocation Gets all locations and the supported resource providers for each location.
New-AzResourceGroup Creates an Azure resource group.
New-AzStorageAccount Creates a Storage account.
Get-AzStorageAccountKey Gets the access keys for an Azure Storage account.
New-AzStorageAccountKey Regenerates an access key for an Azure Storage account.

Next steps

For more information on the Azure PowerShell module, see Azure PowerShell documentation.

Additional storage PowerShell script samples can be found in PowerShell samples for Azure Blob storage.