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.
- ################# Azure Blob Storage - PowerShell ####################
-
- ## Input Parameters
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1122020"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to get all the blobs
- Function CreateSASToken
- {
- Write-Host -ForegroundColor Green "Creating an account level SAS Token.."
- ## Get the storage account
- $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
- ## Get the storage account context
- $ctx=$storageAcc.Context
- ## Creates an account-level SAS token.
- New-AzStorageAccountSASToken -Context $ctx -Service Blob,File,Table,Queue -ResourceType Service,Container,Object -Permission "racwdlup"
- }
-
- CreateSASToken
-
- ## Disconnect from Azure Account
- 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.