DEV Community

Cover image for Creating A Virtual Machine Using CLI in Azure
Jetsumz
Jetsumz

Posted on

Creating A Virtual Machine Using CLI in Azure

1. The first step would be logging into your Azure portal account.
Image description

2. The second step would be opening the opening the command line interface on the portal.
Image description

3. For the purpose of this particular session, we will be using Powershell instead of Bash. Use the dropdown button to switch to Powershell.
Image description

4. After switching to Powershell, it should look like similar to the image below.
Image description

5. Create a Resource Group using the syntax below.
New-AzResourceGroup -Name 'myCoolerRg' -Location 'EastUS'
Image description

6. Create the virtual machine using the syntax below.

New-AzVm `
-ResourceGroupName "myCoolerRg" `
-Name "myVMps" `
-Location "WEST US" `
-VirtualNetworkName "myVnetPS" `
-SUbnetName "mySubnetPS" `
-SecurityGroupName "myNSGPS" `
-PublicIpAddressName "myPublicIpPS"

Enter fullscreen mode Exit fullscreen mode

Image description

7. Notice that the code snippet specified above is a multi-line code. This is achieved with the use of the backtick symbol
Image description

8. After running the code, you will be prompted to enter the username and password that will later be used to access the virtual machine.
Image description

9. Ensure that the password created follows the guidelines specified below otherwise it may not work.
Image description

10. After inputting the username and password, you should get the prompt below signifying that the Virtual Machine is being created.
Image description

11. Once successfully created, you will see a message indicating the creation of the Virtual Machine and the attributes that you had earlier specified.
Image description

Top comments (0)