Use PowerShell to create a Storage Account in Azure

You’ll need to sign up for an Azure account if you don’t already have one: https://azure.microsoft.com. There’s a free trial if you want to try it out.

One thing I would suggest if you've never used Azure is to spend a little time in the GUI (your Azure account's portal website) learning about it before you start trying to manage it with PowerShell. That's the same advice I would give to anyone wanting to do something with PowerShell. For example, if you want to create an Active Directory user with PowerShell and you've never created one in the GUI. Start with the GUI, learn the process, and then move to PowerShell which will give you a better understanding of what you're trying to accomplish.

There's a Microsoft article on How to install and configure Azure PowerShell that will walk you through the process of installing the Azure PowerShell module so there's no reason to duplicate that information here.

azure-storage7a.jpg

At this point, you should already have your Azure account connected as shown in that article by using the Add-AzureAccount PowerShell cmdlet.

1Add-AzureAccount

azure-storage8a.jpg

One of the first things that you'll need to do is to setup a storage account. This is necessary before you can start creating VM's in Azure with PowerShell, but first you'll need to decide what tier and instance type of VM that you want to create so that you can create the storage account in an Azure datacenter that supports your desired VM type. The virtual machine tier and instance type information can be found here.

Based on that information, I want to create a basic tier instance type A1. I also want to use one of Azure's datacenters that exists in the United States so based on that information, I'll use PowerShell to determine which Azure locations support my desired configuration:

1Get-AzureLocation |
2Where-Object {$_.Name -like '*US*' -and $_.VirtualMachineRoleSizes -contains 'Basic_A1'} |
3Select-Object -Property Name

azure-storage1a.jpg

There are certain restrictions on what characters the storage account name can contain. See this article on Azure Storage Naming Rules for details. You'll receive an error if you try adding something like a dash to it as shown in the following example:

1New-AzureStorageAccount -StorageAccountName 'mikefrobbins-storage' -Location 'South Central US'

azure-storage2a.jpg

1New-AzureStorageAccount : Specified argument was out of the range of valid values.
2Parameter name: parameters.Name
3At line:1 char:1
4+ New-AzureStorageAccount -StorageAccountName ‘mikefrobbins-storage’ -L …
5+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+ CategoryInfo : NotSpecified: (:) [New-AzureStorageAccount], ArgumentOutOfRangeException
7+ FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Microsoft.WindowsAzure.Commands.ServiceManagement.Sto
8rageServices.NewAzureStorageAccountCommand

Removing the dash from the name allows the storage account to be created successfully:

1New-AzureStorageAccount -StorageAccountName 'mikefrobbinsstorage' -Location 'South Central US'

azure-storage3a.jpg

Now to view the details of this new storage account that's been created:

1Get-AzureStorageAccount -StorageAccountName mikefrobbinsstorage

azure-storage4a.jpg

The description is where you can set a name that is more specific:

1Set-AzureStorageAccount -StorageAccountName mikefrobbinsstorage -Description 'Mike F Robbins Storage Account for Azure South Central US Datacenter'

azure-storage5a.jpg

Now to double check to make sure the new description has been applied:

1Get-AzureStorageAccount -StorageAccountName mikefrobbinsstorage

azure-storage6a.jpg

µ