Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$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 = ""
$endip = ""
$storageaccountname = "$($webappname)media"
# 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 "" -EndIpAddress ""
# 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)"
Write-Host "SQL server address: $($sqlserverName)"
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
You can’t perform that action at this time.