Provisioning a new virtual machine from a specific image

In the previous section, we decided we would use the 2016-Datacenter image for a new virtual machine. In this section, I am going to explain how to deploy a virtual machine based on the 2016-Datacenter image, within the WindowsServer offer, from the  MicrosoftWindowsServer publisher.

To deploy the new virtual machine, which we are going to call myVM2, you need to first capture some credentials to use as the local admin for the new virtual machine. To specify the local admin credentials for the new virtual machine, run the following command:

$cred = Get-Credential

To deploy a new virtual machine (called myVM2), using the preceding information, run the New-AzureRmVm command in a PowerShell session that's been connected to your Azure tenant:

New-AzureRmVm `
-ResourceGroupName "VMLab" `
-Name "myVM2" `
-Location "EastUS" `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNSG" `
-PublicIpAddressName "myPublicIpAddress2" `
-ImageName "MicrosoftWindowsServer:WindowsServer:2016-Datacenter:latest" `
-Credential $cred `
-AsJob

You might notice that the preceding command looks very similar to the original command that we used earlier in this book to provision the initial virtual machine (myVM) using the default image. However, if you look closely at this new iteration, you'll see two new switches added to it. You'll see ImageName specified, as well as AsJob. These are two new switches that were not included when the MyVM virtual machine was first deployed.

The ImageName switch specifies the value returned by the Get-AzureRmVMImageSku command in the previous section. This is the switch that tells Azure what specific image to deploy the new virtual machine from.

The AsJob switch creates the virtual machine as a background task and returns control of the PowerShell prompt to you, so you can continue working without needing to wait for the previous command to complete.

Since this command is deploying a virtual machine, it can take a while to complete. After a few minutes (usually 15 minutes or so), the new myVM2 virtual machine will be deployed:

Before continuing, you can run the following Get-AzureRmVm command and confirm that the myVM2 virtual machine is deployed and running:

Get-AzureRmVm -ResourceGroupName VMLab -Name MyVM2 -status

Assuming you did everything right, you will be able to see the following output, indicating that the new myVM2 virtual machine has been deployed and is running:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.241.228