Essentials to create a Virtual Machine using Powershell on Azure
Essentials to create a Virtual Machine using Powershell on Azure
There are various options/parameters which would be used while creating a Virtual Machine either by using Azure Portal or by using Powershell AZ module
Prerequisites:
- Powershell 6+
- Az Module
In this section, we’ll discuss the following parameters:
- Resource Group Name
- It is a kind of virtual container. Each resource in Azure should be aligned to a Resource Group
- Virtual Machine Name
- That is the user’s choice. You can keep any name of your virtual machine.
- Location
- In which location do you want to spin-up your virtual machine. Azure has various regions across the globe. It is advised to read about latency and available services in azure regions beforehand.
- Virtual Network Name
- You can either create a new virtual network or assign the existing one to your virtual machine
- Subnet Name
- The subnet is an integral part of a virtual network. You can either create a new subnet or assign the existing subnet to your virtual machine
- Security Group Name
- Network Security Group is also known as Firewall. It protects from direct access to your virtual machine. It could be directly assigned to a virtual machine or the subnet. That is a design choice.
- Public IP Address Name
- It is the address through which this machine could be accessed
- Open Ports
- If you want various options to allow your virtual machine to be accessed like HTTP, HTTPS, RDP etc.
- Port 80 is for HTTP, Port 443 is for https (secure connection), Port 3389 for RDP access.
Create a VM using Powershell:
Ensure you have 6.0.0 or above Powershell version installed and AZ module installed before running the command on Powershell
C:\> New-AzVM -ResourceGroupName “azrgdemo” -Name “azvmdemomachine” -Location “EastUS” -VirtualNetworkName “azvnetdemo” -SubnetName “default” -SecurityGroupName “azdemoNSG” -PublicIpAddressName “azdemoipaddr” -OpenPorts 80,3389,443
Though there are a couple of other optional parameters that you could also pass in the command like Tags I have skipped at this moment.
When you run the above command, the Powershell will ask for the credentials
Example:
User: abhishekmaitrey
Password for user abhishekmaitrey: **********
Now, the Powershell AZ module will execute this command and start the VM creation process. This activity may take some time. Once the command executed successfully, you will be notified with some detailed information on a new virtual machine like
Virtual Machine Id – It is generally a hashed value like GUID
Fully Qualified Domain Name