3
votes

I am attempting to create a storage group and am running into some issues.

Here is the code I am working with:

$StorageAccountName = 'myazurefileshare'
$Share              = 'FileShare'
$Location           = 'North Europe'
$ac = Get-AzureStorageAccount -StorageAccountName $StorageAccountName -ErrorAction SilentlyContinue
"Storage account exists? [$(if ($ac) {$true} else {$false})]"
If (!$ac)  # Does not exist - so create it
   {
     Write-Verbose "Storage Account [$StorageAccountName] in [$Location] does not exist"
     Write-Verbose "Creating Storage Account [$StorageAccountName] in [$Location]"
     New-AzureStorageAccount -StorageAccountName $StorageAccountName `
        -Location $Location -type 'Standard_GRS'
   }

If I run this with verbose on, I get this:

VERBOSE: 19:58:11 - Begin Operation: Get-AzureStorageAccount
VERBOSE: 19:58:12 - Completed Operation: Get-AzureStorageAccount
Storage account exists? [False]
VERBOSE: Storage Account [myazurefileshare] in [North Europe] does not exist
VERBOSE: Creating Storage Account [myazurefileshare] in [North Europe]
VERBOSE: 19:58:12 - Begin Operation: New-AzureStorageAccount
New-AzureStorageAccount : ConflictError: The storage account named 'myazurefileshare' is already taken.
At line:13 char:6
+      New-AzureStorageAccount -StorageAccountName $StorageAccountName  ...
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureStorageAccount], CloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.StorageServices.NewAzureStorageAccountCommand

VERBOSE: 19:58:14 - Completed Operation: New-AzureStorageAccount

So - when I do Get-AzureStorageAccount, it tells me that the storage account does not exist. But when I try to create it, it fails as the name exists. Needless to say, Test-AzureName is consistent with the error returned:

C:> Test-AzureName -Storage myazurefileshare
VERBOSE: The storage account named 'myazurefileshare' is already taken.
True

So why does Get-AzureStorageAccount not return the actual storage account that Test-Azurename says exists?

Clues?

(and sorry for earlier formatting issues!)

1
If I am not mistaken, Get-AzureStorageAccount tries to find a storage account in your subscription whereas Test-Azurename and New-AzureStorageAccount runs in global context to check for the availability of the name. So if the storage account you're trying to create is created by somebody else but is not in your subscription, Get-AzureStorageAccount will return null but Test-Azurename and New-AzureStorageAccount will fail. - Gaurav Mantri
I just worked out what was happening - and you are right. The name I was trying to use was being used by someone else. I now have that bit of the code working just fine Thanks! - Thomas Lee

1 Answers

7
votes

storage account names are unique across the subscriptions. When you try to list the account with given name, it is not found under your subscription but is taken by someone else and will not let you create another storage account with the same name.