Microsoft Azure Storage and Database Part 10 – Configure Stored Access Policy Using PowerShell

Hello Everybody,
Hope you all are doing good !!! 🙂 .
In one of our last article we have discussed how to configure Stored Access Policy and SAS based on Stored Access Policy. Today in this article, we will discuss how to configure Stored Access Policy using PowerShell.
Previous Azure series :
- Learn Basics Of Azure Networking In 60 Hours
- Learn Basic Of Azure Active Directory And Azure Identity And Access Management
- Azure DevOps – Learn at one place
If you have missed our previous articles on Azure Storage and Database Series, please check it in following links.
Part 1 – Overview Of Azure Storage and Database
Part 2 – Azure Storage Account
Part 4 – Work With Azure Blob Storage
Part 5 – Storage Explorer For Azure Storage
Part 6 – Azure Blob Storage – Snapshot Using Storage Explorer
Part 7 – Azure Blob Storage – Shared Access Signature (SAS)
Part 8 – Secure Azure Storage Using Stored Access Policy
Part 9 – Secure Azure Storage Using RBAC
Next Article : Part 11 – Get Shared Access Signature (SAS) Using PowerShell
Let’s check through Azure Portal, if we have any Stored Access Policy exist. As we can see in the following figure, I have one Stored Access Policy, which we have created in our previous lab.

Now we will open Window PowerShell and execute following commands as showing in the following figure.
$StartTime = Get-Date
$EndTime = $startTime.AddDays(4)
$ctx4 = New-AzStorageContext -ConnectionString “DefaultEndpointsProtocol=https;AccountName=kj21storageacount;AccountKey=S4bSWdLylyTXoZwDzUh+zAVapA/f2S821gjNj24oqdzaFpR2ePVd7ApfWJEoyxVNbvkk9NpHV/BDxbF8Emjg2g==;EndpointSuffix=core.windows.net”
New-AzStorageContainerStoredAccessPolicy -Context $ctx4 -Container “kj-container” -Policy “FourDays-rwdl-Access_KJ-Container” -Permission rwdl -StartTime $StartTime -ExpiryTime $EndTime
When I was trying to configure Stored Access Policy, I have come across couple of issues. Followings are the details of those issues.
- The Specified Resource Does Not Exist – Status : 404 – ErrorCoad : ResourceNotFound
- Type Cast Issue – Cannot convert the Microsoft.WindowsAzure.Commands Storage.AzureStorageContext
But after fixing those issue, when i execute the above command, it successfully created the new Stored Access Policy.

In the following figure it shows that we have the second Stored Access Policy successfully created.

I hope this is informative to you. Please let me know if I missed anything important or if my understanding is not up to the mark.
Next Article : Part 11 – Get Shared Access Signature (SAS) Using PowerShell
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more.
If you have any suggestion / feedback / doubt, you are most welcome. Stay tuned on Knowledge-Junction, will come up with more such articles.
Thanks for reading 🙂 .
14 Responses
[…] one of our previous article we have discussed how to Configure Stored Access Policy Using PowerShell. Today in this article we will discuss how to get Shared Access Signature (SAS) URI using […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Next Article : Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Part 10 – Configure Stored Access Policy Using PowerShell […]
[…] Chapter 10 – Configure Stored Access Policy Using PowerShell […]
You must log in to post a comment.