Skip to content

Instantly share code, notes, and snippets.

@ErikHen
Last active September 5, 2017 13:55
Show Gist options
  • Save ErikHen/bd16b2303b3cae344c87454e67547568 to your computer and use it in GitHub Desktop.
Save ErikHen/bd16b2303b3cae344c87454e67547568 to your computer and use it in GitHub Desktop.
$webappname = "myepienvironment" # Application name (lowercase alphanumeric only)
$subscriptionname = "My subscription name"
$resourcegroupname ="$($webappname)-resourcegroup"
$location="West Europe"
$sqlservername = "$($webappname)-sqlserver"
$sqladminlogin = "SaUser"
$sqlpassword = "YourSecretAdminPassword1"
# The ip address range that you want to allow to access your SQL server - change as appropriate
$startip = "111.112.113.114"
$endip = "111.112.113.114"
$storageaccountname = "$($webappname)media"
Login-AzureRmAccount
# Change subscription (not needed if you only have access to one subscription)
Get-AzureRmSubscription –SubscriptionName $subscriptionname | Select-AzureRmSubscription
# Create resource group if it doesn't exist.
$resourcegroup = Get-AzureRmResourceGroup -Name $resourcegroupname -ErrorAction SilentlyContinue
if ($resourcegroup -eq $null)
{
New-AzureRmResourceGroup -Name $resourcegroupname -Location $location
}
# Create App Service Plan ("Free" tier).
New-AzureRmAppServicePlan -Name "$($webappname)ServicePlan" -Location $location -ResourceGroupName $resourcegroupname -Tier Free
# Create web app.
New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan "$($webappname)ServicePlan" -ResourceGroupName $resourcegroupname
Set-AzureRmWebApp -ResourceGroupName $resourcegroupname -Name $webappname -WebSocketsEnabled $true #Episerver needs websockets
Set-AzureRmWebApp -ResourceGroupName $resourcegroupname -Name $webappname -PhpVersion "Off" #Php is not needed, so turn it off
# Create SQL server if it doesn't exist
$sqlserver = Get-AzureRmSqlServer -ServerName $sqlserverName -ResourceGroupName $resourceGroupname -ErrorAction SilentlyContinue
if ($sqlserver -eq $null)
{
New-AzureRmSqlServer -ResourceGroupName $resourcegroupname -ServerName $sqlservername -Location $location -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sqladminlogin, $(ConvertTo-SecureString -String $sqlpassword -AsPlainText -Force))
New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourcegroupname -ServerName $sqlservername -FirewallRuleName "MyOfficeIp" -StartIpAddress $startip -EndIpAddress $endip
New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourcegroupname -ServerName $sqlservername -FirewallRuleName "AllowAzureService" -StartIpAddress "0.0.0.0" -EndIpAddress "0.0.0.0"
}
# Create blob storage account if it doesn't exist
$storageaccount = Get-AzureRmStorageAccount -Name $storageaccountname -ResourceGroupName $resourcegroupname -ErrorAction Ignore
if ($storageaccount -eq $null)
{
New-AzureRmStorageAccount -Location $location -Name $storageaccountname -ResourceGroupName $resourcegroupname -SkuName Standard_LRS -Kind BlobStorage -AccessTier Hot
$storageaccount = Get-AzureRmStorageAccount -Name $storageaccountname -ResourceGroupName $resourcegroupname
}
$storagekey = Get-AzureRmStorageAccountKey -ResourceGroupName $resourcegroupname -AccountName $storageaccountname
# Output values
Write-Host "====================================================================`n"
Write-Host "Site url: $($webappname).azurewebsites.net"
Write-Host "SQL server address: $($sqlserverName).database.windows.net"
Write-Host "SQL server user: $($sqladminlogin)"
Write-Host "SQL server password: $($sqlpassword)"
Write-Host "Blob storage name: $($storageaccountname)"
Write-Host "Blob storage key: $($storagekey.Value[0])"
Write-Host "`n===================================================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment