Last active
April 4, 2017 01:26
-
-
Save PCfromDCSnippets/5d61041ed12e27b3842589dc057c8aec to your computer and use it in GitHub Desktop.
Create Resource Group and Storage Account
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
#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