Sunday, 10 May 2015

Deploying VM in Virtual Network through PowerShell

I have already posted articles regarding creating VM’s through PowerShell and also came across the step of assigning VM’s to Virtual Network via management portal.

In this article, we will have a look on how to deploy VM in Virtual Network through PowerShell.
Following things to be added while deploying VM via PowerShell so as to ensure VM to be placed within mentioned Network Subnet under Virtual network.

$vnetName = "SQUONS-NETWORK"             # Name of Virtual Network
$subnet = "SQUONS-SUBNET"                       # Name of Subnet created under Virtual Network
New-AzureQuickVM -Windows `
                                     -ServiceName $serviceName `
                                     -Name $vmName `
                                     -ImageName $imageName `
                                     -AdminUsername $adminUser `
                                     -Password $password `
                                     -Location $location `
                                     -InstanceSize $size `
                                     -SubnetNames $subnet `
                                     -VNetName $vnetName

Below example depicts how the VM is deployed in Virtual Network through PowerShell.

$adminUser = "Shakeel"
$password = "##########"
$serviceName = "squons-vnet"                    # ServiceName means CloudService name e.g. “squons”
$location = "West US"                      # In which location you want to deploy your VM e.g. "West US"
$size = "Medium"                                  # Size/Tier name e.g. “Small/Medium/Large” etc
$vmName = "SQUONS-VNET-VM1"                   # Name or Virtual Machine e.g. “SQUONS-VM1”
$imageFamily = "Windows Server 2012 R2 Datacenter"
$vnetName = "SQUONS-NETWORK"                       # Name of Virtual Network
$subnet = "SQUONS-SUBNET"                          # Name of Subnet created under Virtual Network
$imageName = Get-AzureVMImage |
                                                             where { $_.ImageFamily -eq $imageFamily } |
                                                             sort PublishedDate -Descending |
                                                             select -ExpandProperty ImageName -First 1
New-AzureQuickVM -Windows `
                                     -ServiceName $serviceName `
                                     -Name $vmName `
                                     -ImageName $imageName `
                                     -AdminUsername $adminUser `
                                     -Password $password `
                                     -Location $location `
                                     -InstanceSize $size `
                                     -SubnetNames $subnet `
                                     -VNetName $vnetName



To verify the properties of deployed VM, use the following syntax:

Get-AzureVM –NAME “VM Name” –ServiceName “Cloud Service Name

 

No comments:

Post a Comment