page contents My title page contents A Blog on Tools, Techniques and Announcements: Implementing Azure Virtual Machine using ARM

Wednesday, December 20, 2017

Implementing Azure Virtual Machine using ARM


Note that the command are listed below
Login-
AzureRmAccount
Get-AzureRmSubscription
Select-AzureRmSubscription –SubcriptionName ‘Test’
Get-Command –Module AzureRM.compute
image

Reference :https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-ps-create/#example

Step 1: Install Azure PowerShell

This is something that we have covered in  the previous chapters

Step 2: Create a resource group

Get-AzureRmLocation | sort Location | Select Location
Choose one of the Locations
Then Save the LocationName in a Variable
$locName = "centralus"
Replace the value of $rgName with a name for the new resource group. Create the variable and the resource group.
$rgName = "mygroup1"
New-AzureRmResourceGroup -Name $rgName -Location $locName

Step 3: Create a storage account

A storage account is needed to store the virtual hard disk that is used by the virtual machine that you create.
Replace the value of $stName with a name for the storage account. Test the name for uniqueness.
$stName = "999storage"
Get-AzureRmStorageAccountNameAvailability $stName
If this command returns True, your proposed name is unique within Azure. Storage account names must be between 3 and 24 characters in length and may contain numbers and lowercase letters only.
Then Run  the Command to create the storage
$storageAcc = New-AzureRmStorageAccount -ResourceGroupName $rgName -Name $stName -SkuName "Standard_LRS" -Kind "Storage" -Location $locName
 

Step 4: Create a virtual network

All virtual machines are part of a virtual network.
Virtual Networks Have Subnets,
you cannot proceed further without a Subnet, hence it is important to create a Virtual network and  then  a Subnet
New-AzureRmVirtualNetwork -ResourceGroupName mygroup1 -Name TestVNet ` -AddressPrefix 192.168.0.0/16 -Location centralus  
Save the Value of the Virtual Network in a Variable
$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName mygroup1 -Name TestVNet
Create a Subnet
Add-AzureRmVirtualNetworkSubnetConfig -Name FrontEnd `-VirtualNetwork $vnet -AddressPrefix 192.168.1.0/24

Step 5: Create a public IP address and network interface

To enable communication with the virtual machine in the virtual network, you need a public IP address and a network interface.
  1. Replace the value of $ipName with a name for the public IP address. Create the variable and the public IP address.

    $ipName = "myIPaddress1"
    $pip = New-AzureRmPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic
  2. Replace the value of $nicName with a name for the network interface. Create the variable and the network interface.

    $nicName = "mynic1"
    $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Locat


Step 6: Create a virtual machine

Now that you have all the pieces in place, it's time to create the virtual machine.
  1. Run the command to set the administrator account name and password for the virtual machine.

    $cred = Get-Credential -Message "Type the name and password of the local administrator account."
    The password must be at 8-123 characters long and meet three out of the four complexity requirements: one lower case character, one upper case character, one number, and one special character. See more about username and password requirements.
  2. Replace the value of $vmName with a name for the virtual machine. Create the variable and the virtual machine configuration.

    $vmName = "myvm1"
    $vm = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_A1"
    See Sizes for virtual machines in Azure for a list of available sizes for a virtual machine.
  3. Replace the value of $compName with a computer name for the virtual machine. Create the variable and add the operating system information to the configuration.

    $compName = "myvm1"
    $vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $compName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
  4. Define the image to use to provision the virtual machine.

    $vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
    See Navigate and select Windows virtual machine images in Azure with PowerShell or the CLI for more information about selecting images to use.
  5. Add the network interface that you created to the configuration.

    $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
  6. Replace the value of $blobPath with a path and filename in storage that the virtual hard disk will use. The virtual hard disk file is usually stored in a container, for examplevhds/WindowsVMosDisk.vhd. Create the variables.

    $blobPath = "vhds/WindowsVMosDisk.vhd"
    $osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + $blobPath
  7. Replace The value of $diskName with a name for the operating system disk. Create the variable and add the disk information to the configuration.

    $diskName = "windowsvmosdisk"
    $vm = Set-AzureRmVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage
  8. Finally, create the virtual machine.

    New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm














image


You can  finally verify the machine using the variable
image
image




No comments:

Post a Comment