Azure: How to check storage account exists in Azure with Get-AzureStorageAccount
I would suggest using the Test-AzureName cmdlet to determine if it exists. So, something like this.
if (!(Test-AzureName -Storage $Name)){ Write-Host "Creating Storage Account $Name" New-AzureStorageAccount -StorageAccountName $Name -Location $Location }
You can use Test-AzureName for other services too, such as Cloud Services, WebSites, and ServiceBus. It returns True if it exists, False otherwise.
Try this:
$Name = "myStorageAccount"$Location = "myLocation"Write-Host "[Start] creating $Name storage account $Location location"try{ Get-AzureStorageAccount –StorageAccountName $Name -ErrorAction Stop | Out-Null Write-Host "$Name storage account in $Location location already exists, skipping creation" }catch{ Write-Host "[Finish] creating $Name storage account in $Location location" New-AzureStorageAccount -StorageAccountName $Name -Location $Location -Verbose }