Access Blob storage using SAS Key via PowerShell

Alex Palmer 0 Reputation points
2024-09-03T09:55:03.15+00:00

Hi

I want to be able to access Blob storage using a SAS key in PowerShell. I have the SAS key set up on the storage account, limited to the IP of the server I'm running the PowerShell from. I want to be able to use the key without signing into Azure or using a Storage Account Key. Is this possible?

If I run
$SasToken = New-AzStorageContainerSASToken -Name "backup" -Permission "rad"

$Context = New-AzStorageContext -StorageAccountName "storage1" -SasToken $SasToken

I get
User's image

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,137 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,517 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinod Kumar Reddy Chilupuri 230 Reputation points Microsoft Vendor
    2024-09-09T02:10:39.94+00:00

    Hi Alex Palmer,
    Welcome to Microsoft Q&A, thanks for posting your query

    A shared access signature (SAS) provides delegated access to Azure resources. A SAS gives you granular control over how a client can access your data.

    You can specify which resources are available to the client. You can also limit the types of operations that the client can perform and specify the amount of time for which the actions can be taken.

    A SAS is commonly used to provide temporary and secure access to a client who wouldn't normally have permissions. An example of this scenario would be a service that allows users read and write their own data to your storage account.

    Yes, you can access Blob storage using a SAS key in PowerShell without signing into Azure or use a Storage Account Key.

    • You don't need to generate a new SAS token with New-AzStorageContainerSASToken if you already have one. Instead, directly create a storage context using the SAS token.
    • The "New-AzStorageContext" cmdlet creates a storage context using the specified storage account name and SAS token.
    • Code:
      Assign your existing SAS token.
      $SasToken = "your_existing_sas_token"
      Create a new storage context using the SAS token.
      $Context = New-AzStorageContext -StorageAccountName "storage1" -SasToken $SasToken
    • Once you have created the storage context, you can use it to perform operations on the container, such as uploading or downloading blobs.
    •  you can go through this below links.
    • Reference: https://video2.skills-academy.com/en-us/powershell/module/az.storage/new-azstoragecontext?view=azps-12.3.0&viewFallbackFrom=azps-10.17.0

    Please let us know if you have any further queries. I’m happy to assist you further. 


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.