Issue with New-AzStorageContext – The Specified Resource Does Not Exist – Status : 404 – ErrorCoad : ResourceNotFound

Hello EveryBody,

Hope you all are doing good !!!

Issue :

During my journey with Azure, when I was trying to create a Stored Access Policy using following script snippet for my blob container using PowerShell one Error occur and the Error Coad is ResourceNotFound and the status is 404. Following is the details of the error.

Figure 1 – Get Azure Storage Context Issue

New-AzStorageContainerStoredAccessPolicy: The specified resource does not exist.
Status: 404 (The specified resource does not exist.)
ErrorCode: ResourceNotFound
Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id: 8cf31c3e-801e-0013-4592-531893000000
x-ms-client-request-id: cc2bcfbb-6a7a-4461-8982-2cef4b2273d5
x-ms-version: 2020-04-08
x-ms-error-code: ResourceNotFound
Date: Fri, 28 May 2021 07:24:43 GMT
Content-Length: 223
Content-Type: application/xml

I tried to find the root cause of this issue. Initially I thought , may be I have given some wrong parameters or due to any typo but when I check thoroughly found there is no such mistake. Then I google for some time and found one article (, where it stated that, the way I have created the Azure Storage Context object is not supporting Get/New-AzStorageContainerStoredAccessPolicy because the context was created using Oauth authentication. The problem appears when OAuth is used and If the storage account context created by using ” -UseConnectedAccount”.

we can find all operations supported by Oauth in this doc, and we can see Get/New Container Stored Access Policy is not in the list, so it’s not supported by Oauth. So the failure is by design.

Solution :

Here the solution is to use different overloaded method to create StorageContext object. Initially we ware using following script.

$ctx4 = -StorageAccountName kj21storageacount -UseConnectedAccount

Instead of the above I have used the following script by passing the connection string.

$ctx4 = New-AzStorageContext -ConnectionString “DefaultEndpointsProtocol=https;AccountName=kj21storageacount;AccountKey=S4bSWdL345345@$@@$S821gjNj24oqdzaFpR2ePVd7ApfWJEadsfdfSDF453$k9NpHV/BDxbF8Emjg2g==;”

In this way we have resolved the above issue and move one step further towards our Stored Access Policy creation 🙂 .

After resolving the above issue I faced the next issue regarding type casting. I will discuss this in my next article.

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.

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 🙂 .

Manas Ranjan Moharana

I'm a proud Indian, Son, Husband, Father, Author, Blogger, Self motivated person. I lives in Pune, Maharashtra and working for, to build Azure Solutions and Share Point Solutions.Microsoft certified Professional with 14 years of IT experience. Interest in learning and sharing something new, to be healthy.

You may also like...

2 Responses

  1. May 31, 2021

    […] The Specified Resource Does Not Exist – Status : 404 – ErrorCoad : ResourceNotFound […]

  2. May 31, 2021

    […] my last article, we have seen how to resolve an issue with getting Azure Storage Context . After fixing that issue, […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: