Author : MD TAREQ HASSAN | Updated : 2020/11/09

Prerequisites

Create required resources beforehand to use those during VM creation. If not created beforehand, required resources will be created during VM creation.

Create Resource Group:

Create required resources:

AZ module installation

Create Virtual Machine

Login to Azure when using local PowerShell or PowerShell ISE

Login-AzAccount       # Login-AzureRmAccount

Connect-AzAccount

Commands to create VM (Cloud Shell is preferred)

# 1
Get-AzSubscription    # Get-AzureRmSubscription

# 2
Set-AzContext -SubscriptionName "Free Trial" # Set-AzureRmContext

# 3
$location = "japaneast"

# 4
$rgName = "IaaS-ps-rg"

# 5
$credential = Get-Credential # set id & password for VM

# 6
New-AzResourceGroup -Name $rgName -Location $location # New-AzureRmResourceGroup

# 7
New-AzVm `
    -ResourceGroupName $rgName `
    -Name "IaaS-ps" `
    -Location $location `
    -VirtualNetworkName "IaaS-ps-vnet" `
    -SubnetName "IaaS-ps-subnet" `
    -SecurityGroupName "IaaS-ps-nsg" `
    -PublicIpAddressName "IaaS-ps-ip" `
    -OpenPorts 80,3389 `
    -Credential $credential  # New-AzureRmVm

# 8
$ipAddress = Get-AzPublicIpAddress -ResourceGroupName Iaas-ps-rg `
         | Select-Object -ExpandProperty IpAddress  # Get-AzureRmPublicIpAddress

# 9
$ipAddress # just to see ip address of the created vm

Connect to virtual machine

See: Connecting to virtual machine