Created
April 8, 2016 02:37
-
-
Save rayterrill/cd7ef7332cfbcd40e39482ca998c366f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$resourceGroupName = "TESTSERVERS" | |
$location = "West US" | |
$storageType = "Standard_GRS" | |
function createStorageAccount($storageAccountPrefix) { | |
$storageAccountCreated = $False | |
#storage account names need to be globally unique | |
#loop until we find a storage account name that works | |
while ($storageAccountCreated -eq $False) { | |
$randomNumber = Get-Random | |
$storageName = $storageAccountPrefix + $randomNumber | |
try { | |
$storageAccount = New-AzureRMStorageAccount -ResourceGroupName $resourceGroupName -Name $storageName -Type $storageType -Location $location | |
$storageAccountCreated = $True | |
} catch { | |
#turn on debug mode to see failed attempts to create storage accounts | |
Write-Debug "Storage account $($storageName) was taken. Trying again..." | |
} | |
} | |
return $storageAccount | |
} | |
$storageAccount = createStorageAccount -storagePrefix "TESTSERVERSTORE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment