How to create a VM with PowerShell using Azure
Tags: virtualmachine, powershell, azure
Published: 2022-04-24 15:59:15

For everyone who is looking for how to create a Windows Virtual Machine (VM) with PowerShell using Azure. This walkthrough will show how one can create a VM using PowerShell. 

Sign in to the **Azure Portal**
From the Portal, open the **Azure Cloud Shell** by clicking on the icon just after the search box![Cloud Shell icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dr1wv3ojnxoev7lpfhij.jpg)
When prompted to select either Bash or PowerShell, select **PowerShell**
On the **You have no storage mounted** screen, click on show advance settings![you have no storage mounted](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uj1r395foj3m7n11k398.PNG)
Create new for Resource Group, Storage account and File share and proceed to create storage![create storage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwfsr37z00gt9f3qeap1.PNG)
Verify your new resource group by running the following command in the POwerShell window. Press Enter on your keyboard to run the command below
_Get-AzResourceGroup | Format-Table_
Create a virtual machine by pasting the following command into the terminal window
_New-AzVm `
 -ResourceGroupName "mytrial" `
 -Name "myVMPS" `
 -Location "West Europe" `
 -VirtualNetworkName "myVnetPS" `
 -SubnetName "mySubnetPS" `
 -SecurityGroupName "myNSGPS" `
 -PublicIpAddressName "myPublicIpPS"_

**Note** - The resource group name should be the one created before as seen in above picture(mytrial) and the location should be one on the cloud shell region (West Europe)
After entering the command, you will be prompted to provide a username (**azureuser**) and Password (**Pa$$w0rd1234**). 
Also note that the result of the command can come back by indicating the location for the virtual machine you are about to create is not available. 
The way to rectify this is to create a new resource group (without closing the PowerShell window) by typing resource group in the search box and select create

![resource group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aeay5q4vvs6k8x3qbmqq.PNG)
Create a new resource group and change the region to the one that is available
![create a resource group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cfyfb6qtl20eixie04c3.PNG)
**Hint:** you will be able to know what location is available through the virtual machine page. Search for virtual machine in the search box and go straight to region, pick a region and make sure the region as a size available (under size). Once its available, choose it as your new location when creating the new resource group. Make sure you do not create the virtual machine, this is just for you to know what location and size is available.
If there is a new resource group and location, make sure the command above is edited with the new resource group and location.

Once the VM is created, close the PowerShell session Cloud Shell pane.
In the search box, search for virtual machines and verify that (**myVMPS** - the virtual machine name) is running.

Access the new virtual machine and review the **Overview** and **Networking** settings to verify your information was successfully deployed.