First off, I am not a developer and most certainly not a scripting expert. I have just recently “discovered” the phenomena of a function in PowerShell and the usage of Try{} Catch{} and am just trying to put this knowledge to work.

Why would I want to make a script if i can use the GUI?

Sure, the GUI is easy to use, performs quite well most of the time and..you can see:-)

Scripting comes to mind when you have enough of the slugish performance of the online Azure GUI, like me, or to create a bulk of machines, let’s say 10. Some with different characteristics than the other, maybe all the same. I do know technicians who will actually make a list with servers and specs and just do everything manual. Hey, whatever works for you. If you want to be able to have more control over the process, make it sharable, versioned, repeatable. Then at minimum you should go for a scripted solution. In following posts i will inform on how to do the same as this script and more, with the Azure SDK for Visual Studio.

To get started we need the Azure PowerShell module installed on our local machine. And of course an account on Azure. You can start a free trial here.

Install Azure PowerShell

Azure PowerShell recommends installing from the PowerShell Gallery. You need the PowerShellGet module to use the PowerShell Gallery. Alternatively, use the Web Platform Installer (WebPI), or the MSI file available from GitHub.3

Connect to an Azure account

You can run the cmdlets from the standard Windows PowerShell console, or from PowerShell Integrated Scripting Environment (ISE). The cmdlets need your subscription information so they can manage your services.

Type “Login-AzureRMAccount” in your console window and press Enter.

Enter the email account you used to subscribe to Azure.

Azure CMDlets

Now that we have confirmed that the Azure PowerShell Module is properly installed, I will run you through some basics.

To retrieve information from an object or objects we use “Get” followed by a dash(-) and then the method keyword.

We will use the following methods to retrieve info:

Get-AzureRmSubscription

Get-AzureRmResourceGroup

Get-AzureRmResources

Get-AzureRmWebApp

Get-AzureVM

Get-AzurRMVirtualNetwork

Get-AzureRmAvailabilitySet

Get-AzureRmNetworkInterface

Get-AzureRmPublicIpAddress

Get-AzureRmStorageAccount

Replacing the Get statement with “Remove” or “New” or “Select” is all it takes to meet our other wishes with regards to the script. You gotta love PowerShell.

I decided to create a separate PowerShell file for all the different functions. I call it common.ps1.

For logging purposes I also created a separate PowerShell file called logging.ps1

The main file will be AzureAdmin.ps1. This is basically a file from where I call a menu which can call all the functions from common.ps1.

For starters I would like to login to Azure. Off course i could have just typed

here and there. This is because I would like to use the values maybe in a later stage of the script.

Now this same trick of building menu’s where I can make a selection, I will do a lot. It is because you would want to be able to make a choiche for an existing resource or creating a new one for instance. This goes almost definitely for the Resource Group, but I also need it for Location.