New-AzureStorageAccount : Specified argument was out of the range of valid values. Parameter name: parameters.Name

Recently I have been working on automating deploying an IaaS infrastructure on Azure.. Part of this required me creating my storage accounts.  The automation would allow users to add or remove storage accounts in a list and create them all in one bunch.  I am doing this through a XAML form.  What I found is people would enter in capitol letters.  If you are not familiar with creating storage accounts, when you create them in the portal you can only specify lowercase letters and numbers, this is the same with the New-AzureStorageAccount cmdlet.



To get around this, in your script you can use Regex Replace and .ToLower to convert the value to lowercase and numbers and letters only.  Where below $sa is an object that I store my values like StorageAccountName, Label, Description and AffinityGroup.

$StorageAccountName = [Regex]::Replace($sa.Name.ToLower(), '[^(a-z0-9)]', '')

Comments (3)
  1. Steve Ognibene says:

    Thanks! This helped me.

  2. kb says:

    This is helpful!

  3. Andrew Masse says:

    Ran into this exact problem deploying from ARM template. Interesting that the ARM template auto-generates the storage account name with upper-case letters…

Comments are closed.

Skip to main content