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

SARASWAT CHETAN 91 Reputation points
2021-02-25T16:04:36.64+00:00

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
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
1,560 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vaibhav Chaudhari 37,771 Reputation points
    2021-02-25T16:23:36.827+00:00

    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