A Step-by-Step Guide to Easily Creating Azure Virtual Machines with PowerShell
Tags: azure, tutorial, beginners, devops
Published: 2023-05-11 21:33:50

In a recent blog article, we demonstrated how to [Create a Virtual Machine in Less Than a Minute with ARM Template and Azure Quick Start](https://dev.to/henriettatkr/create-a-virtual-machine-in-less-than-a-minute-with-arm-template-and-azure-quick-start-1bbb). However, there are other ways of creating an Azure virtual machine, and in this blog article, we will show you how to achieve this using PowerShell.

## Creating an Azure virtual machine using PowerShell

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. It allows you to perform various tasks and automate processes, including creating and managing virtual machines in the cloud. Let's get started with the steps to create an Azure virtual machine using PowerShell.

## Step 1:
Log in to the Azure Portal using this [link](https://azure.microsoft.com/en-gb/free/) 

## Step 2:
Once you are logged in, you should see a search bar at the top of the page. To the right of the search bar, there should be an icon that looks like a **>_** symbol as highlighted in the image below. This is the Cloud Shell icon.
Click on the Cloud Shell icon to open the Cloud Shell window.

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

## Step 3:
Select the PowerShell option to open the PowerShell environment within the Cloud Shell.

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

## Step 4: 
Fill in the storage account and file sharing fields if requested to create storage. 

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

## Step 5:
Create a Resource Group
To create a resource group, you can use the command below

```
New-AzResourceGroup -Name 'myCoolRg' -Location 'EastUS'
```

**Note:** Replace **_myCoolRg_** with the name of your resource group and **_EastUS_** with the location of your choice.

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

## Step 6:
Once you have created a resource group, you can create a new virtual machine using the code below

```
New-AzVM -ResourceGroupName 'myCoolRg' -Name "myvMps" -Location "West US" -VirtualNetworkName "myVnetPS" -SubnetName "mySubnetPS"-SecurityGroupName "myNSGPS"-PublicIpAddressName "myPublicIpPs"
```
Once you hit enter, you will be prompted to supply a username and password 

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

## Step 7: 
Verify the virtual machine creation
Once the virtual machine creation process is complete, you will see the screen below 

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

## Step 8:
Navigate to Azure Resource Group page in the portal and click con the Resource Group created to see the running Virtual Machine 

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

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

## Step 9: 
The Virtual machine can be delete using this command 

```
Remove-AzResourceGroup -Name 'myCoolRg'
```

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


Creating an Azure virtual machine using PowerShell is a straightforward processing you can create yours using the steps above.