question

SARASWATCHETAN-7930 avatar image
0 Votes"
SARASWATCHETAN-7930 asked SARASWATCHETAN-7930 commented

New-AzStorageContainer command not accepting valid -context created from New-AzStorageContext

New-AzStorageContext is creating a context named as below
Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext
However New-AzStorageContainer is accepting "-context" with below type Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext

Issue is arising when in a PS script post creation of a resource group and further a storage account, I am unable to create a container within that storage account as New-AzStorageContainer doesn't accept's -StorageAccountName as a parameter.
So while drawing a context around it and using that context to create the subsequent container it is showing different abstract type.

azure-storage-accounts
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MS Team,

Any suggestions or approach to resolve the context issue.

0 Votes 0 ·

1 Answer

VaibhavChaudhari avatar image
0 Votes"
VaibhavChaudhari answered SARASWATCHETAN-7930 commented

I could create a container just by running below 3 lines. Could you try this code?

 connect-azaccount
    
 $ctx = New-AzStorageContext -StorageAccountName "mygen2accountname" -StorageAccountKey "mystorageaccountkey"
    
 New-AzStorageContainer -Name "mycontainer" -Context $ctx


Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Vaibhav for the suggestion. I already tried it, however facing the below error using the -context saved from the storage account.

72173-image.png


Looks like the same issue as raised above due to the parent class used in the cmdlet is different as compared to the one mentioned in below snapshot which is getting generated while creating the context for the storage account.


72211-image.png


0 Votes 0 ·
image.png (28.9 KiB)
image.png (3.3 KiB)

Well. I'm sorry it took some time from Azure Resource Manager to publish the storage account and when I retried the same, the container got created.

So now the only issue remains around the parent class which context is using or shouldn't the New-AzStorageContainer have a "-StorageAccountName" as a parameter to pass to instead of always saving the context around the storage account.


0 Votes 0 ·

I have tried producing same scenario multiple times and facing the issue of creating the container using the "New-AzStorageContext command, that too after putting in a wait-Event of more than 120 seconds, however it fails showing below error.

72169-image.png


Now it seems like the context being created by the storage account is somewhat different in comparison to the one being created under New-AzStorageContext. Below is the one being created under the storage account.

72186-image.png



This is definitely an issue it seems..

0 Votes 0 ·
image.png (77.8 KiB)
image.png (44.4 KiB)
Show more comments
VaibhavChaudhari avatar image VaibhavChaudhari SARASWATCHETAN-7930 ·

Sorry, I am not able to reproduce the issue. Maybe first check if RG, Storage account is created first and only try to run the code to create a container.

0 Votes 0 ·
Show more comments