One of the core services within Microsoft Azure is the Storage Account service. There are many service that utilize Storage Accounts for storing data, such as Virtual Machine Disks, Diagnostics logs, and others. You can also use the Azure Storage Account service to store your own data; such as blobs or binary data. This article takes a look at the Azure PowerShell cmdlets / commands for creating both Azure Storage Accounts and Storage Containers.



Create Azure Storage Account using PowerShell

To create a new instance of the Azure Storage service within your Azure Subscription, you can run the following command:

New-AzStorageAccount -ResourceGroupName {resource-group-name} `
    -Name {storage-account-name} `
    -Location {location} `
    -SkuName {sku}

Be sure to replace the placeholders in the above example with the appropriate values:

-ResourceGroupName: This parameter needs to be set to the Resource Group the newly created Storage Account will be organized within.

-Name: This parameter defines the Name of the Storage Account resource that will get provisioned in your Azure Subscription. Can also be named -AccountName or -StorageAccountName.

Naming Requirements: Azure Storage Accounts have slightly different naming requirements than most other resource types in Azure:

  • must be unique across all customers using Azure Storage Accounts within Azure; as it’s used as part of the DNS name for the service.
  • Must be 3 to 24 characters long
  • Can only contain lowercase letters and number (no special characters)

-Location: This parameter defines the Location where to provision the Storage Account. This is the Azure Region that you desire to use for hosting the resource.

-SkuName: This parameter defines the SKU or pricing tier to use for the Storage Account.

Azure Storage SKUs (Pricing Tiers)

The -SkuName parameter of the New-AzStorageAccount cmdlet must be set to a valid pricing tier (SKU) for the service.

Here are the SKUs that can be used when provisioning an Azure Storage Account and the values to set to the -SkuName parameter of the cmdlet:

SKU Description
Standard_LRS Locally-redundant storage
Standard_ZRS Zone-redundant storage
Standard_GRS Geo-redundant storage
Standard_RAGRS Read access geo-redundant storage
Premium_LRS Premium locally-redundant storage
Premium_ZRS Premium zone-redundant storage

Here’s an example of creating a new Azure Storage Account using the premium zone-redundant storage SKU:

New-AzStorageAccount -ResourceGroupName Build5NinesRG `
    -Name build5ninesblobs `
    -Location northcentralus `
    -SkuName Premium_ZRS

Create Azure Storage Container using PowerShell

The most common use of Azure Storage Accounts is to store binary data or Blobs (binary large objects). To do this, you need to create at least one storage Container within the Storage Account that you will be storing blobs within.

To create storage containers within an existing Azure Storage Account, you can use the following command:

New-AzStorageContainer -Name {container-name}

However, before you can create the storage container, you must first create a reference to a Storage Account Context, then you will use this context to tell the New-AzStorageContainer cmdlet which storage account to create the storage container within.

You can use the Get-AzStorageAccount cmdlet to retrieve a storage account context and assign it to a variable. Alternatively, you could also set the variable at the time of creating the storage account as well.

# Retrieve an existing Storage Account reference
$storageContext = Get-AzStorageAccount -ResourceGroupName Build5NinesRG `
    -Name build5ninesblobs

# Capture reference to a Storage Account at creation
$storageContext = New-AzStorageAccount -ResourceGroupName Build5NinesRG `
    -Name build5ninesblobs `
    -Location northcentralus `
    -SkuName Premium_ZRS

# Retrieve the Context from the Storage Account
$storageContext = $storageAccount.Context

Notice, that when using the Get-AzStorageAccountcmdlet, you will need to pass in the Resource Group name and the Storage Account name to retrieve the context for.

Once you have the context for the Storage Account, you can then go ahead and start creating one or more storage containers within the account, like the following:

New-AzStorageContainer -Name mycontainer `
    -Context $storageContext `
    -Permission Off

Notice the New-AzStorageContainer command does require a couple parameters:

-Name: This is the Name to use for the storage container that is created.

-Context: This is the Storage Account Context to use for creating the new container.

-Permission: This specified the public access level for the container. By default, the value of Off is used to restrict access to only the storage account owner.

Here are the full options for the -Permission parameter and the description of what they do:

Permission Description
Container Provides read access to blob data within the container via anonymous requests, including the ability to enumerate the contents of the container. Permission is limited to only this container.
Blob Provides read access to blob data within the container via anonymous requests, so long as clients have the full URL for the blobs. They will not be able to enumerate the contents of the container.
Off Restricts access to only the Storage Account owner.

Install Azure PowerShell Az.Storage Module

By default, the Az.Storage module should already be installed for you to use when you install the Azure PowerShell SDK. If you do get errors attempting to execute Azure Storage cmdlets, then it is likely you may need to install the module on your machine first.

If you do need to install the Az.Storage module, you can use the following PowerShell command to install it:

Install-Module -Name Az.Storage


Microsoft MVP

Chris is a Microsoft MVP and has 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

Pin It on Pinterest