Deploy Azure VM in Powershell

Deploy Azure VM in Powershell

Tempo de leitura: 4 minutos

Hello folks,

Disclaimer – I won’t explain what each cmdlet does, and its parameters are out of the scope of this post and the PowerShell’s syntax, please, to find out more  look at Azure Powershell documentation

It’s been a long time since I have written in my blog. After adapting myself to a new country since I moved out of Brazil, I found out time to focus my energy and passion of sharing knowledge with the SQL community tech over again

In this post, we will learn how to deploy a VM in Azure trough the Powershell script. I created this to meet a need in my company to deploy a lot of similar virtual machines in azure which comes from a pre-defined list of VMs in a .csv file. In addition, would like to thank you Felipe Santos (Dicas de Infra) for helping me out on this.

Let’s get started. You should start opening your windows PowerShell ISE tool

Once it’s opened, we should start coding, and your first step must connect into your subscription

PS – for the command above a window will pop up asking your azure credentials

if you have more than one subscription, keep in mind in perfmon these commands and select the correct one you want, for our example, I will pick my visual studio subscription up

As we well know, all resources in azure must be in a resource group(TCRG in my case) and they should belong to a given location (North Europe in my case, because it is the nearest location where I am today), to avoid re-type it over and over again, I will put them in variables and reuse If needed.

If we go to the Azure portal, we will look an RG (resource group) created there

From here, I am going to create networking stuff such as vnet, subnet, NSG, and subnet inbound and outbound rules.

PS – Please, pay atentention that I allowed any connection (inbound and outbound), DON’T DO THAT IN PROD.

So far how our deployment looks like:

PS – note that I haven’t created the IP yet, it is going to be done within a for each later.

Once the networking configuration is done, I will get all VM properties from my VMList.csv file that are being kept at the c:\temp\ path. Let’s look inside of this file

The PowerShell will load all proprieties from this file into an object. Within the for each statement, I am going to create the IP, interface, SQL server offer, SQL edition, etc.

The command above will take a couple of minutes to run, once It’s done you will see a message like that:

PS – Keep in mind that I went through the Azure Powershell interface to take these values out to have them added to my solution if you need something different from that, please, referral to the Microsoft documentation to figure out what you will need to implement.

This is how our solution should look like int the end of the deployment

Click at the SQLVM01 VM > connect and download the RDP to your machine and sign it up with the credentials previously created in the .csv file

Your machine will be ready to be used! Hope you had enjoyed it and see ya!

Was there another way of implementing and improving this solution? Of course, I could create many “IFs” for validating if something exists or not and so on, but It wasn’t needed on my scenario, feel free to use this solution and improve it.

Um comentário

  1. […] continuing our last post, let’s assume after you have created the virtual machine, you need to add a managed disk to be […]

Deixe uma resposta

%d blogueiros gostam disto: