Retrieve a storage context with ARM

Retrieve a storage context with ARM

Q. How do I retrieve a storage context to an ARM storage account?

A. Azure Resource Manager handles resources very differently from Azure Service Manager however for PowerShell cmdlets that use a storage context based on the storage account key (or using a shared access signature (SAS)) and the storage account name. The PowerShell below fetches the storage account key and creates a context that could then be used for any storage cmdlet that uses contexts such as copy operations and Azure Files.

$AzStorAccName = 'savtechsalrsscus'
$AzResGroup = 'rg-scusa'
$AzStrAct = Get-AzureRmStorageAccount -Name $AzStorAccName -ResourceGroupName $AzResGroup
$AzStrKey = Get-AzureRmStorageAccountKey -Name $AzStorAccName -ResourceGroupName $AzResGroup
$AzStrCtx = New-AzureStorageContext $AzStorAccName -StorageAccountKey $AzStrKey[0].Value

#Example creation of Azure Files share with the storage context created
$imgs = New-AzureStorageShare imgs -Context $AzStrCtx 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish