Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PCfromDCSnippets/5d61041ed12e27b3842589dc057c8aec to your computer and use it in GitHub Desktop.
Save PCfromDCSnippets/5d61041ed12e27b3842589dc057c8aec to your computer and use it in GitHub Desktop.
Create Resource Group and Storage Account
#region Create Resource Group
$rg = Get-AzureRmResourceGroup -Name $resourceGroup -Location $location -ErrorAction SilentlyContinue
if ($rg) {
Write-Host "$resourceGroup resource group already exists..."
}
else {
Write-Host "Creating $resourceGroup Resource Group..."
$rg = New-AzureRmResourceGroup -Name $resourceGroup -Location $location -Force
}
#endregion
#region Create Storage Account
$sa = $rg | Get-AzureRMStorageAccount -StorageAccountName $storageAccountName -ErrorAction SilentlyContinue
if ($sa) {
Write-Host "$storageAccountName storage account already exists..."
}
else {
Write-Host "Checking to see if $storageAccountName is valid..."
$valid = Get-AzureRmStorageAccountNameAvailability -Name $storageAccountName.ToLower()
if ($valid.NameAvailable) {
Write-Host "$storageAccountName is valid..."
Write-Host "Creating $storageAccountName Storage Account..."
$sa = $rg | New-AzureRMStorageAccount -StorageAccountName $storageAccountName.ToLower() -Location $location -Type "Standard_GRS" -EnableEncryptionService File
}
else {
Write-Host $valid.Message
Exit
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment