Remember the time when setting up an Episerver environment took hours? I don’t mean your local dev-environment, I mean a test or production environment with IIS and SQL server. Maybe you got access to one or two freshly installed Windows machines where you needed to install windows features, IIS addons, SQL server, et.c. And more often than not, you had forgotten something
Now we have Amazon web services and Azure Web apps that makes this process much simpler, and quicker. But it still requires quite a lot of point and click, waiting for certain process to finish before you can continue, and so on. And since there is a possibility of forgetting something, or making a mistake, it’s going to happen.
This blog post will show you how you can automate setting up an Episerver CMS environment in Azure. The environment is similar to the one described in Episerver’s guide, but without the service bus (but that can be added, of course). This environment can easily be scaled up to be used as a production environment.
Automate is king!
To be able to manage Azure resources using Powershell you need to install the Azure Resource Manager modules. In Windows 10 it’s as easy as running PowerShell in administrator mode and type:
If you’re running other versions of windows or have trouble installing, take a look here.
Then you need to allow powershell to run your script:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
You can read more about execution policies here.
At the top there are some variables that you might want to change:
- $webappname is the name you want to use for your application. Make sure that the name isn’t in use already.
- $subscriptionname is the name of the subscription that should be used. Search for “subscriptions” in Azure portal to see all subscriptions you have access to, and just copy/paste the name. If you only have access to one subscription, you can remove those parts of the script.
- The script doesn’t create an SQL database, it just creates the SQL server. You add the database later on by importing a .bacpac file, that you can export from e.g. your local development environment. The script opens the SQL server firewall for the ip-number(s) specified in $startip & $endip. When the database import is done, you can remove that firewall rule. Use whatsmyip.org if you don’t know your external ip.
You can run the script by just copy/paste the script to your Powershell prompt, or save the script to a file and type .\YourFileName.ps1 .
When finished, the script prints out all the values you need for your Web.config/transformation file.
You should try and make a script like this idempotent. If something goes wrong, you should be able to update the part that fails, and then run the complete script again.
Remember the time when setting up an Episerver environment took more than a few minutes 🙂
4 thoughts on “Use PowerShell to set up an Episerver environment in Azure”
Nice! Thanks for sharing 🙂
Great stuff, thanks!
Good stuff. Was doing it all manually again yesterday, thinking that there has to be a better way to do this. Now there is!