Deploying a Resource Group and Virtual Machine using PowerShell
Tags: powershell, resourcegroup, virtualmachine, cloudshell
Published: 2023-05-05 12:01:50

Azure PowerShell is a collection of cmdlets that is used for managing Azure resources directly from PowerShell. It is a cross-platform PowerShell module that is compatible with Windows, macOS and Linux computers
It requires Windows PowerShell or PowerShell environment to function.

The following are the basic steps to take in creating a resource group and deploying virtual machine using PowerShell

1)Log in to Azure portal and click on Cloud Shell

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j1lzjg5setmcujjk6ttn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08fc0olxg0lbp6v7k9mq.png)
Select PowerShell
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5xsp51kyie23j0ockj1.png)

2)Create Storage account if required to do so especially when it is indicated that no storage is mounted. But in this case we have an existing Storage account

3)Create the Resource Group before creating the Virtual machine which is a resource.
Copy the command line you want to use to create the resource group that I named myResourceGroup and paste it on the terminal window

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l9cgeghtm8lurt5jfmb8.png)


Then press Enter

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/51kn8l49n5fhry9z8gsp.png)
The resource group has been created

4)Copy the command that you want to use to create the virtual machine and paste it on the Powershell terminal window.I will name the virtual machine myVM
Then press enter and input the username and password
My Username is Azureuser and Password is Password123* 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z0g4n26v6krryqx8m874.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11n4l91q1p3126xbrwv1.png)

The virtual machine, myVM has been created

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awz143b60cmx5sbhirck.png)

5)To confirm this, go to azure portal and check for the name of the Resource group and the Virtual Machine, myResourceGroup and myVM

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yx42n08ow5zo72deqi0y.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n2vipt1azh6grzdsh4e7.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rn618jgzepep4dfi116.png)




6)To connect to the Virtual machine, Click on Connect

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/57wkep68y4g343h377po.png)
Download the RDP file and open it

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/we11510pgsj58bp9lklk.png)
Click on Connect and input the Username:Azureuser and Password:Password123* 
Then click ok

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f4hbeiacqyxrh3ycpy65.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3ix3e60hlxwfzihdqh5.png)
Click Yes

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5hvnbs1wx4e4jty8nc0m.jpg)
We have successfully connected to the Virtual Machine

7)Check Azure Advisor for best practices that can be applied for the virtual machine created
Go back to myResourceGroup and click on myVM


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0n429honij1t24vti6i3.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yeal3fbsrfgiqyiuac6l.png)

Click on the Hamburger Icon on the top left-hand corner of Azure portal and Select Advisor from the Menu

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lekcpbjjepj147vjyxp4.png)
Yeah! The Advisor has brought up one recommendation


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/96bbueswd4t8z09qlb8m.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gejdd0d1mzaspnt84wgs.png)

The recommendation is to use NAT gateway for Outbound Connectivity
Yes! Microsoft Azure is very friendly and interesting to use

If you find this article helpful, kindly give a feedback