DEV Community

Tolu Iyoriobhe
Tolu Iyoriobhe

Posted on

How to create a VM with PowerShell using Azure

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 boxCloud Shell icon
When prompted to select either Bash or PowerShell, select PowerShell
On the You have no storage mounted screen, click on show advance settingsyou have no storage mounted
Create new for Resource Group, Storage account and File share and proceed to create storagecreate storage
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
Create a new resource group and change the region to the one that is available
create a resource group
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.

Top comments (0)