Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Last active March 7, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichieBzzzt/d60a67fc46ec1a3d2da2f1c447933bcf to your computer and use it in GitHub Desktop.
Save RichieBzzzt/d60a67fc46ec1a3d2da2f1c447933bcf to your computer and use it in GitHub Desktop.
#run once then comment out
#Login-AzureRmAccount
$subscriptionName = ""
$ResourceGroupName = ""
$location = ""
$dataLakeStoreName = ""
$ErrorActionPreference = 'Continue'
Select-AzureRmSubscription -SubscriptionName $subscriptionName
Write-Host "Step 2 - Configure Resource Group" -ForegroundColor White -BackgroundColor DarkGreen
try {
$CheckResourceGroupExists = Get-AzureRmResourceGroup -Name $ResourceGroupName
}
catch {
Write-Host "oh dear" -ForegroundColor Black -BackgroundColor DarkRed
throw
}
if ($CheckResourceGroupExists -eq $false) {
"Resource Group doesn't exist. Creating..."
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location
}
elseif ($CheckResourceGroupExists -eq $true) {
"Resource Group exists."
}
Write-Host "Step 3 - Configure Data Lake Store Account" -ForegroundColor White -BackgroundColor DarkGreen
try {
$CheckDataLakeStoreAccountExists = Test-AzureRmDataLakeStoreAccount -Name $dataLakeStoreName -ErrorAction $ErrorActionPreference
}
catch {
if ($Error[0].Exception.Message -like "% reference not set to an instance of an %") {
Write-Host ("DataLakeStore Account {0} not found, creating" -f $dataLakeStoreName)
}
else {
throw ("Could not determine if Datalake Store Account already exists`n{0}" -f $Error[0])
}
}
if (($null -eq $CheckDataLakeStoreAccountExists) -or ($CheckDataLakeStoreAccountExists -eq $false)) {
try{
Write-Host "Creating Azure Data Lake Store Account" -ForegroundColor White -BackgroundColor DarkCyan
New-AzureRmDataLakeStoreAccount -ResourceGroupName $resourceGroupName -Name $dataLakeStoreName -Location $Location -ErrorAction Stop
}
catch{
Write-Host "Failed to deploy Data Lake Store."
throw $_.Exception
}
}
else {
Write-Host ("Data Lake Store {0} already exists" -f $dataLakeStoreName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment