Introduction

In this blog, you will see how to generate an account-level shared access signature (SAS) token for an Azure Storage account using PowerShell.

Azure Portal

Prerequisites

Install Azure PowerShell Module to run the script.

PowerShell Script

Open Notepad and paste the following script. Save the file as script.ps1.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. ## Connect to Azure Account
  6. Connect-AzAccount
  7. ## Function to get all the blobs
  8. Function CreateSASToken
  9. {
  10. Write-Host -ForegroundColor Green "Creating an account level SAS Token.."
  11. ## Get the storage account
  12. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  13. ## Get the storage account context
  14. $ctx=$storageAcc.Context
  15. ## Creates an account-level SAS token.
  16. New-AzStorageAccountSASToken -Context $ctx -Service Blob,File,Table,Queue -ResourceType Service,Container,Object -Permission "racwdlup"
  17. }
  18. CreateSASToken
  19. ## Disconnect from Azure Account
  20. Disconnect-AzAccount

Open the Windows PowerShell window and navigate to the location where the script file was saved.

Run the following command.

.\script.ps1

SAS Token

Reference

https://docs.microsoft.com/en-us/powershell/module/az.storage/New-AzStorageAccountSASToken?view=azps-3.3.0

Summary

In this blog, you saw how to generate an account-level shared access signature (SAS) token for an Azure Storage account using PowerShell.