In my previous two articles in my section here on VirtualizationAdmin.com I included several excerpts adapted from my book Training Guide: Installing and Configuring Windows Server 2012 R2 (Microsoft Press, 2014) which is available from http://www.amazon.com/exec/obidos/ASIN/0735684332/. These two articles were intended to help you get up to speed on using PowerShell to manage Hyper-V hosts and their virtual machines, and the two articles of interest are:
While reading an article is one way to learn a new skill, it usually takes practice to create confidence and drill things into memory. That's why I'm including one final excerpt from my book, and this time it's two of the hands-on practice exercises that are designed to supplement the material included in the previous two articles above. Note that while the sections below have been excerpted from Chapters 1 and 7 of my book, they have also been modified as necessary to make them suitable for presentation as a self-contained article here on VirtualizationAdmin.com.
Before you begin
To complete the practice exercises you need a minimum of one physical server system available for testing purposes. At least one of these servers should meet the minimum hardware requirements for installing Windows Server 2012 R2, as described here. You might also need to download an evaluation version (.iso file) of Windows Server 2012 R2 from the TechNet Evaluation Center
The goal of these exercises is to provide you with hands-on practice with the following:
- Installing and configuring Hyper-V on Server Core
- Creating and configuring virtual machines
To perform the exercises, you need at least one clean installation of Windows Server 2012 R2 performed using the Server Core installation option. The server should be a stand-alone server belonging to a workgroup, have at least two physical hard disk drives with the second drive formatted as a data volume, have at least two physical network adapters with both configured with static TCP/IP settings, have Internet connectivity, and have no additional roles or features installed. You should be logged on interactively to the server using the default Administrator account. For the purposes of these exercises, the name of the server is assumed to be HOST7 and the data volume is the E drive.
If you want, you can perform these exercises remotely from another computer by enabling Remote Desktop on HOST7 and using Remote Desktop Connection on your computer. If you do this, note that certain actions (such as creating new virtual switches) might temporarily disrupt Remote Desktop connectivity with the remote host.
Exercise 1: Installing and configuring Hyper-V on Server Core
In this exercise, you use Windows PowerShell to install the Hyper-V role, configure virtual machine storage locations, and create virtual switches.
- Log on to HOST7 and type powershell at the command prompt to open a Windows PowerShell prompt.
- Use the Get-WindowsFeature cmdlet to verify that the Hyper-V role and Hyper-V Module For Windows PowerShell are available for installation but the Hyper-V GUI Management Tools are removed and not available for installation.
- Use the Install-WindowsFeature cmdlet to install the Hyper-V role and Hyper-V Module For Windows PowerShell. You can use the –IncludeManagementTools parameter to do this using a single command. Make sure you include the –Restart parameter.
- Once the server has restarted, log on as Administrator, type powershell at the command prompt, and use the Get-WindowsFeature cmdlet to verify that the Hyper-V role and Hyper-V Module For Windows PowerShell have been successfully installed.
- Type mkdir E:\vmstorage to create a new directory on the data drive.
- Use the Get-VMHost cmdlet to display the values of the VirtualHardDiskPath and VirtualMachinePath properties.
- Use the Set-VMHost cmdlet to change the values of the preceding two properties to E:\vmstorage.
- Use the Get-VMHost cmdlet to verify the change you made to the default storage location for virtual machine files.
- Use the Get-VMSwitch cmdlet to verify that there are no virtual switches configured on the host.
- Type Get-NetAdapter and note the names of the two physical network adapters on the host.
- Use the New-VMSwitch cmdlet to create a new virtual switch of External type named CONTOSO. Ensure that the new switch is connected to one of the network adapters on the host.
- Use the New-VMSwitch cmdlet to create a second virtual switch of External type named MANAGEMENT. Ensure that the new switch is connected to the other network adapter on the host.
- Use the Get-VMSwitch cmdlet to verify that both virtual switches have been successfully created.
- Leave yourself logged on to HOST7 and proceed to the next exercise.
Exercise 2: Creating and configuring virtual machines
In this exercise, you use Windows PowerShell to create a new virtual machine, enable and configure Dynamic Memory on the virtual machine, change the number of virtual processors on the virtual machine, enable and configure bandwidth management on the network adapter, and perform a checkpoint of the virtual machine.
- Type New-VM –Name SERVER8 –Path E:\vmstorage –NewVHDPath server8.vhdx –NewVHDSizeBytes 100GB –SwitchName CONTOSO to create a new virtual machine named SERVER8 that has a dynamically expanding virtual hard disk of size 100 GBs and a virtual network adapter connected to the CONTOSO virtual switch.
- Type Get-VM | fl ConfigurationLocation and verify that the configuration files for the virtual machine are stored in the E:\vmstorage\SERVER8 directory.
- Type dir "E:\vmstorage\SERVER8\Virtual Hard Disks" and verify that a file named server8.vhdx exists in this location.
- Type Set-VM –Name SERVER8 –MemoryStartupBytes 2GB to configure the Startup RAM setting as 2 GBs.
- Type Set-VM –Name SERVER8 –DynamicMemory to enable the Dynamic Memory feature on the virtual machine.
- Type Set-VM –Name SERVER8 –MemoryMinimumBytes 1GB to configure the Dynamic Memory Minimum RAM setting as 1 GB.
- Type Set-VM –Name SERVER8 –MemoryMaximumBytes 4GB to configure the Dynamic Memory Maximum RAM setting as 4 GBs.
- Type Set-VMMemory –VMName SERVER8 –Buffer 40 to configure the Dynamic Memory Memory Buffer setting as 40 percent.
- Type Get-WmiObject Win32_Processor | fl NumberOfLogicalProcessors to view the number of logical processors on the host system.
- Type Get-VMProcessor –VMName SERVER8 | fl Count to view the number of virtual processors currently configured on the virtual machine. (This should be one processor.)
- Type Set-VMProcessor –VMName SERVER8 –Count 2 to change the number of virtual processors on the virtual machine from one to two processors.
- Type Get-VMProcessor –VMName SERVER8 | fl Count again to confirm the change.
- Type Get-VMNetworkAdapter –VMName SERVER8 to view information about the virtual network adapter on the virtual machine. Make a note of the name of the adapter. (It should be named Network Adapter.)
- Type Set-VMNetworkAdapter –VMName SERVER8 –Name "Network Adapter" –MinimumBandwidthAbsolute 50000000 to assign a minimum bandwidth value of 50 Mbps to the virtual machine’s virtual network adapter.
- Type Set-VMNetworkAdapter –VMName SERVER8 –Name "Network Adapter" –MaximumBandwidth 200000000 to assign a maximum bandwidth value of 200 Mbps to the virtual machine’s virtual network adapter.
- Type Checkpoint-VM –VMName SERVER8 –SnapshotName "Guest OS not installed" to perform a checkpoint of the virtual machine.
- Type dir "E:\vmstorage\SERVER8\Snapshots" and verify that the checkpoint files have been created.
- The remaining steps in this practice exercise are optional because of the amount of time it might take to perform them.
- Type Install-WindowsFeature –Name Server-Gui-Mgmt-Infra –Restart to convert your Server Core installation to a Minimal Server Interface installation. Because the feature binaries will need to be installed from Windows Update, this step might take some time to complete.
- Once the server has restarted and you have logged on again, Server Manager should automatically open. When it opens, launch the Add Roles And Features Wizard and install the Hyper-V GUI Management Tools feature, which is found under Role Administration Tools\Hyper-V Management Tools on the Features page of the wizard.
- Select the Hyper-V page in Server Manager, right-click HOST7, and select Hyper-V Manager to open the Hyper-V Manager snap-in.
- Use the Hyper-V Manager snap-in to verify all of the configuration steps you performed in the two practice exercises in this chapter.
Suggested practice exercises
The following additional practice exercises are designed to give you more opportunities to practice what you’ve learned and to help you successfully master the lessons presented in this chapter.
- Practice 1 - Modify the two practice exercises so that they use as few Windows PowerShell commands as possible to perform all the configuration actions required.
- Practice 2 - Build on the second practice exercise by adding a second virtual network adapter to the virtual machine, connecting the second adapter to the second virtual switch on the host, and configuring NIC Teaming for the virtual machine.
- Practice 3 - Modify the second practice exercise to create and configure a Generation 2 virtual machine.
- Practice 4 - Start a virtual machine and resize its virtual hard disk while it is still running. Then try exporting the live virtual machine and importing it onto another host.
There are additional practice exercises in my book so if after performing the ones in this article you still want to gain more hands-on experience with Hyper-V and other capabilities of Windows Server 2012 R2 you might want to purchase my book from Amazon at http://www.amazon.com/exec/obidos/ASIN/0735684332/.
I also recommend that if you aren't already a subscriber to our newsletter WServerNews that you go to http://www.wservernews.com today and click Subscribe in the toolbar and sign up for this free weekly newsletter that focuses on the administration, management and security of the Windows Server platform in particular and cloud solutions (including Microsoft Hyper-V virtualization) in general.