How to create the Azure Storage context using PowerShell?

PowerShellSoftware & CodingMicrosoft Technologies

Storage context is helpful when you are working with the Storage accounts in the PowerShell session. It is like authenticating for Azure storage. Generally, we use the Azure storage account key and the connection string to create the Azure storage context.

To create a new storage context, we need to use the New-AzStorageContext command but to use this command we need a storage account key or the connection string.

We will use here Storage account key. We have the resource group “Az204” and the Storage account name “az204storage05june” which are stored in a variable.

$rg = "az204"
$storageaccount = "az204storage05june"

To get the storage account key,

$key = (Get-AzStorageAccountKey -ResourceGroupName $rg -
Name $storageaccount)[0].Value

To generate the storage context,

$context = New-AzStorageContext -StorageAccountName $storageaccount -
StorageAccountKey $key

Output

You can use this storage context in the various storage commands to deal with the storage operations.

raja
Published on 01-Sep-2021 07:48:38
Advertisements