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 |
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]
[!code-powershellmain]
Run the following command to remove the resource group, storage account, and all related resources.
Remove-AzResourceGroup -Name rotatekeystestrg
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. |
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.