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

SARASWAT CHETAN 91 Reputation points

New-AzStorageContext is creating a context named as below
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

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

    $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