Create a Simple Azure Web App with PowerShell

Hello, this post will show you the steps to create a free, very simple web app in the Microsoft Azure platform using PowerShell.

You will need an existing subscription or sign up for a new one to follow this post. The app service plan selected is the free tier so you will not be charged / count against your Azure credits.

Visio diagram of azure resource group, app service plan and web app

Use must have Azure PowerShell installed. You can get it from the Azure Microsoft site.

azure-powershell

Authenticate to Azure using Azure Resource Manager:

You can list your subscriptions with the following command (the command on the second line will output just the subscription names):

Select the subscription you want to use:

Create a Resource Group:

Tags are a great way to manage resources and are created in PowerShell using a hashtable.

Create an App Service Plan:

Create a Web App:

Note: The web app name must be globally unique. Creating the web app will create the URL: http://webappname.azurewebsites.net.

If your deployment fails, check for the error message: New-AzureRmWebApp : Website with given name simple-web-app134 already exists.

Change the name of the web app or add a random number onto the end.

That’s it. You should now be able to browse to the default template by entering the URL: yoursitename.azurewebsites.net.

Browsing to the newly created site in google chrome http://simple-web-app134.azurewebsites.net/

To delete all of the resources (warning, this will delete everything in the resource group, make sure you are targeting the correct resource group). Add the -Force switch parameter if you don’t want the confirmation prompts:

This is handy when using the app service plans that cost money. I sometimes create a standard plan for trying out deployment slots, so I will use it while testing, then delete it afterwards. If I need it again, I’ll simply run the PowerShell commands again.

I’ve scripted this out and put it on github with variables if you’re interested in taking a look.

That’s it for now, cheers.

Unblocking Files downloaded from the Internet

First off, make sure you trust the source of where you downloaded the files from, only download from legitimate sites you trust and check the SSL certificate if needs be.

Browse to the excellent Sysinternals page on Microsoft’s technet site. Right click the Download Sysinternals Suite link and select “Save link as…” and choose a location to save it to your PC.

If you were to right click on the download zip file and extract the contents and run the programs or view the help files, you will get the Open File – Security Warning dialogue box pop up each time you run it and the help files will not have any contents.

Open File Security Warning
Open File Security Warning

To remove this warning (you of course got the file(s) from a trustworthy source), you can right click on the downloaded zip file, select “Properties”, check the “Unblock” checkbox and click apply. When you extract the zip file, all the files will be unblocked.

unblock a file
Unblock a file

To do this in PowerShell use the Unblock-File command.

This will have the same effect checking the Unblock checkbox.

If you’ve already extracted the files and forgot to unblock them, use the PowerShell command again with the path to the folder containing the files with \* on the end.

 

Azure PowerShell login and create resource group

I’ve been doing lots of work with Azure recently (especially using PowerShell) so thought I’d dump some of the stuff I’ve learnt along the way here… it’s been a while.

This small guide will show you how to login to Azure using PowerShell, view and select your subscriptions and then create a Resource Group that will be provisioned in the Azure Portal.

I’ve messed about with the classic portal a bit, but Resource Manager (RM) is the way to go… you’ll see Rm in the PowerShell nouns to signify that it is a Resource Manager cmdlet.

First you need to install Azure PowerShell to get all that Azure PowerShell goodness… once you’re done (the instructions are clear and easy to follow) come back here and continue below.

Login to your Azure RM account

Get Azure RM subscriptions

Set your Azure RM subscription to work in (one of mine is called Pay-As-You-Go)

Create an Azure RM resource group

This creates a Resource Group called ps-test in the North Europe region with the tag “Created By Matt”

Go to the portal and you should see the newly created resource group (make sure you have selected the correct subscription if you have more than one).

Azure Resource Group deployed by PowerShell
Azure Portal

 

Tags are great and an excellent way to organise your resources, you can also use them to report on costs and usage.

That’s a simple demo of login into Azure with PowerShell, selecting a subscription and then deploying a resource group which is used as a container to help keep track of resources for VMs, Apps, Databases etc.