Quick Reference to build a virtual machine from Azure:

#Create Azure Virtual Machine


$rgName = "<yourResourseGroupName>"

  $subscriptionName = "court services"  #specify name of subscription

  get-AzureRmSubscription -SubscriptionName $subscriptionName | select-azureRMsubscription

  $storageAccName = "<yourResourseGroupName>disks263"

  $rgName = "<yourResourseGroupName>"
  $vnetName = "<yourResourseGroupName>-vnet"

  $location = "Australia Southeast"

  $vnet = get-azurermvirtualnetwork -name <yourResourseGroupName>-vnet -resourcegroupname $rgName

# Create a public IP address and specify a DNS name
$vip = New-AzureRmPublicIpAddress -ResourceGroupName $rgName `
   -Name "tempIP2" -Location $location -AllocationMethod Dynamic `
   -DomainNameLabel “tempip2”

$pip = New-AzureRmPublicIpAddress -ResourceGroupName $rgName -Location $location `
-AllocationMethod Dynamic -IdleTimeoutInMinutes 4 -Name "tempIP2"

# Create a network security group

$nsg =  Get-AzureRmNetworkSecurityGroup -resourcegroupname $rgName -name FTPTest-nsg 

# Create a virtual network card and associate with public IP address and NSG
$nic = New-AzureRmNetworkInterface -Name TempNic -ResourceGroupName $rgName -Location $location `
-SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id
#Create virtual machine
##Create a virtual machine configuration. This configuration includes the settings that are used when deploying the virtual machine such as a virtual machine image, size, and authentication #configuration. When running this step, you are prompted for credentials. The values that you enter are configured as the user name and password for the virtual machine.

# Define a credential object
$cred = Get-Credential

# Create a virtual machine configuration
$vmSize = "Standard_DS1_v2"
PS C:\WINDOWS\System32> Get-AzureRmVMImagesku -location "Australia SouthEast" -publishername MicrosoftWindowsServer -off
er WindowsServer

$availSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rgName -name <availSetName>
$vmConfig = New-AzureRmVMConfig -VMName <machineName> -VMSize  $vmSize -AvailabilitySetId $availSet.Id| `
Set-AzureRmVMOperatingSystem -Windows -ComputerName myVM -Credential $cred | `
Set-AzureRmVMSourceImage -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version latest | `
Add-AzureRmVMNetworkInterface -Id $nic.Id
#Create the virtual machine.

New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmConfig
#Connect to virtual machine
#After the deployment has completed, create a remote desktop connection with the virtual machine.

#Run the following commands to return the public IP address of the virtual machine.

Get-AzureRmPublicIpAddress -ResourceGroupName $rgName | Select IpAddress
#Use the following command to create a remote desktop session with the virtual machine. Replace the IP address with the public IP address of your virtual machine. When prompted, enter the credentials used when creating the virtual machine.

mstsc /v:<Public IP Address>
#Delete virtual machine
#When no longer needed, the following command can be used to remove the Resource Group, VM, and all related resources.

Remove-AzureRmResourceGroup -Name $rgName


About Lei

I am an IT specialist with over 10 year experience - years on Automation, on-Premise or Azure.

I am happy to develop however never want be a full time developer. Only do what I have to do. If it has to be PowerShell,HTML, PHP, CSS, C#, VBS or JS, front end or backend, so be it, doesn't matter!

Spent years with Windows, SCCM, SharePoint, SQL and Exchange servers. For last several years, I have been actively working under On Premise > Azure environment.


Current Certificates:
    Microsoft® Certified-
  • -Enterprise Administrator
  • -Database Administrator
  • -SharePoint Administrator
  • -Administering and Deploying SCCM 2012
Red Hat Certified Technician
ITIL V3 Foundation - Practitioner

Working on Azure Certificates now and hopefully they can stop upgrading their questions one day! GIVE ME A BREAK!

Contact Lei

Name *
Email *
Comments *

Traffic since 10/08/2016

This week518
This month2591

Visitor Info

  • IP:
  • Browser: Unknown
  • Browser Version:
  • Operating System: Unknown

Who Is Online