Professional Documents
Culture Documents
Understanding
Hyper-V
in Windows Server 2012
Brien Posey
Pete Zerger, Chris Henley
Understanding Hyper-V in Windows Server 2012
Contents
Chapter 1. AnIntroduction toHyper-V 3.0 3
Chapter 2. FailoverClustering 30
Chapter 3. Migrations 84
Chapter 4. Managing Virtual Machine Failover 123
Chapter 5. PowerShell Management 144
Chapter 6. Virtual Machine Management 181
Chapter 7. P2V Conversions 222
Chapter 8. Replication 246
Chapter 9. Hyper-V Management 273
Chapter 10. Networking 293
Chapter 11. Backing up Hyper-V 317
Chapter 12. Automation andOrchestration 336
2
Understanding Hyper-V in Windows Server 2012
Chapter 1
AnIntroduction
toHyper-V 3.0
This chapter is designed to get you started quickly with
Hyper-V 3.0. It starts with a discussion of the hardware
requirements for Hyper-V 3.0 and then explains abasic
Hyper-Vdeployment followed by anupgrade from
Hyper-V 2.0 to Hyper-V 3.0. The chapter concludes with
ademonstration of migrating virtual machines from
Hyper-V 2.0 to Hyper-V 3.0
3
Understanding Hyper-V in Windows Server 2012
Hardware requirements
According to Microsoft, the minimum hardware required for deploying
Windows Server 2012 includes:
A 64-bit processor operating at 1.4 GHz or higher
512 MB of RAM
32 GB of hard disk space
A DVD Drive
A monitor and video card with a minimum display resolution of 800 x 600
Keyboard and mouse (or other compatible pointing device)
Internet access
In addition to the hardware requirements listed above, the CPU must support
hardware-level virtualization. It is worth noting that virtualization has been
disabled by default on many servers, so you may need to enable virtualization
through the system BIOS, as shown in Figure 1.1. If your servers BIOS contains
a setting for Data Execution Prevention (DEP), you will need to enable that
setting as well.
4
Understanding Hyper-V in Windows Server 2012
Figure 1.1
5
Understanding Hyper-V in Windows Server 2012
3. Click Next.
4. Click Install Now (Figure 1.3).
Figure 1.3
Choose the edition of Windows Server 2012 that you want to install.
6
Understanding Hyper-V in Windows Server 2012
7
Understanding Hyper-V in Windows Server 2012
Figure 1.7
Select the drive or volume on which you want to install Windows Server 2012.
9. Setup will now begin the installation process (Figure 1.8). After
theWindows installation completes , you must work through a separate
process to install Hyper-V.
Figure 1.8
8
Understanding Hyper-V in Windows Server 2012
Figure 1.9
9
Understanding Hyper-V in Windows Server 2012
Figure 1.11
10
Understanding Hyper-V in Windows Server 2012
11. When the wizard displays the list of available features, click Next.
12. Click Next on the Hyper-V introductory screen.
13. Select the network adapters that you want to make available to your
virtual machines. Be sure to reserve at least one network adapter for host
management traffic (Figure 1.13).
Figure 1.13
11
Understanding Hyper-V in Windows Server 2012
Select Internet Protocol Version 4 (TCP/IPv4) and click the Properties button.
12
Understanding Hyper-V in Windows Server 2012
Figure 1.15
Provision your management NIC with a static IP address and click OK.
13
Understanding Hyper-V in Windows Server 2012
Figure 1.16
3. Verify that the Computer Name tab is selected and then click the Change
button (Figure 1.17).
Figure 1.17
4. Enter a new name for the server and click OK (Figure 1.18).
Figure 1.18
You must restart the server before your changes will take effect.
15
Understanding Hyper-V in Windows Server 2012
16
Understanding Hyper-V in Windows Server 2012
Figure 1.20
You must shut down the virtual machines prior to beginning the upgrade.
2. With Windows Server 2008 R2 still running, insert your Windows Server
2012 installation media and run the Setup program.
3. When the Windows Server 2012 splash screen appears, click Install Now
(Figure 1.21).
Figure 1.21
17
Understanding Hyper-V in Windows Server 2012
Figure 1.22
Choose the edition of Windows Server 2012 that you want to install.
18
Understanding Hyper-V in Windows Server 2012
7. Click Next.
8. When prompted, accept the license agreement and click Next
(Figure1.24).
Figure 1.24
9. Choose the option to Upgrade: Install Windows and keep files, settings,
and applications (Figure 1.25).
Figure 1.25
10. Take a moment to review the Compatibility Report, which informs you
of issues you need to address prior to moving forward with the upgrade
(Figure 1.26). When you are finished, clickNext.
19
Understanding Hyper-V in Windows Server 2012
Figure 1.26
11. At this point, Windows will be installed. The remainder of the upgrade
process is automated.
20
Understanding Hyper-V in Windows Server 2012
Figure 1.27
5. Click Export.
You can monitor the progress of the export by scrolling the Hyper-V Manager
to view the virtual machine Status (Figure 1.29).
21
Understanding Hyper-V in Windows Server 2012
Figure 1.29
You can monitor the export process through the Hyper-V Manager.
Right click-on your the server and select the Import Virtual Machine command from
therightclick menu.
3. When the Import Virtual Machine wizard launches, click Next to bypass
thewizards Welcome screen.
4. Click the Browse button.
22
Understanding Hyper-V in Windows Server 2012
5. Navigate to the folder containing the virtual machine that you want to
import and click the Select Folder button.
6. Choose the virtual machine that you want to import (Figure 1.31).
Figure 1.31
7. Click Next.
8. The next screen asks you to choose an import type (Figure 1.32). Unless
you have a compelling reason to choose one of the other options, it is
usually best to choose the option to Copy the Virtual Machine (Create
a New Unique ID). This allows the exported virtual machine to be
reimported later should the need ever arise.
23
Understanding Hyper-V in Windows Server 2012
Figure 1.32
9. Click Next.
10. The following screen asks if you want to store any of the virtual machine
components in a different location. Generally, it is safe to accept
thedefaults. Click Next.
11. The wizard will now ask where you want to store the imported Virtual
Hard Disks. Select a folder on an appropriate volume and click Next.
12. Verify the summary information screen and click Finish (Figure 1.33).
24
Understanding Hyper-V in Windows Server 2012
Figure 1.33
25
Understanding Hyper-V in Windows Server 2012
Figure 1.34
26
Understanding Hyper-V in Windows Server 2012
cluster, you can start small by building thenew cluster with a minimum number
of cluster nodes and using low-end hardware if necessary. After the migration
process is complete, you can always install Windows Server 2012 onto your
existing cluster hardware, join those servers to the new cluster and then remove
the temporary, low-end servers from thecluster. Dont worry too much about
exceeding the maximum cluster size during the migration process, because
Windows Server 2012 allows up to 63cluster nodes.
As you probably know, Hyper-V 2.0 clusters depend on the use of Cluster Shared
Volumes. When you build the new Hyper-V 3.0 cluster, you must attach the
cluster nodes to the existing cluster shared volume (see Chapter 2 for details).
At this point, both the Hyper-V 2.0 cluster and the Hyper-V 3.0 cluster should be
tied into the same Cluster Shared Volume.
Once the Hyper-V 3.0 cluster is in place, verify that the Hyper-V 2.0 cluster is
still functional and that the virtual machines are still running (there is no reason
why they shouldnt be, because the cluster has not been modified). Now, open
theFailover Cluster Manager on one of your Windows Server 2012 servers
andfollow these steps:
1. Right-click on the cluster name and choose the More Actions | Migrate
Roles commands from the right-click menus (Figure 1.35).
Figure 1.35
27
Understanding Hyper-V in Windows Server 2012
Figure 1.36
4. Select the virtual machines that you plan to migrate and click Next
(Figure1.37).
Figure 1.37
28
Understanding Hyper-V in Windows Server 2012
5. Choose the Virtual Network Switch that the virtual machines should use
after they have been migrated to the new cluster and click Next.
6. The next screen provides an analysis of the migration. You can click
theView Report button to see the full Failover Cluster Pre-Migration
Report. It is worth noting that the report indicates that the cluster group
and the available storage cannot be migrated. This is perfectly normal
andacceptable.
7. Close the report and click Next.
8. Take a moment to verify the information displayed on theConfirmation
screen and click Next.
9. When the migration completes, click Finish.
Please keep in mind that Windows Server 2012 does not perform a live migration
of the virtual machines. When the migration completes, the virtual machines are
still running on the Hyper-V 2.0 cluster, so there are acouple of things that you
need to do to complete the process.
First, shut down the virtual machines on the Hyper-V 2.0 server. Second,
disconnect the Hyper-V 2.0 cluster nodes from the shared storage. If you fail to
do this, virtual machine corruption can occur. Finally, start the virtual machines
on your new cluster. Once the virtual machines are up and running, it is safe to
destroy your Hyper-V 2.0 cluster and re-provision the host servers for use in
thenew cluster.
29
Understanding Hyper-V in Windows Server 2012
Chapter 2
FailoverClustering
Chapter 2 is designed to familiarize you with your options
for Hyper-V clustering. Hyper-V 3.0 allows you to build
acluster with or without shared storage, and this chapter
walks you through both methods. In addition, you will
learn how to provision storage using a new Windows
Server 2012 feature called Windows Storage Spaces.
30
Understanding Hyper-V in Windows Server 2012
Maximum number of
virtual machines in 1000 4000
acluster
Maximum number of
16 63
hosts per cluster
Another major improvement that Microsoft has made with regard to failover
clustering is that they have changed the storage requirements. Prior to Hyper-V
3.0, a Hyper-V cluster depended on the use of a Cluster Shared Volume.
ACluster Shared Volume is a shared storage volume that physically contains all
of thevirtual machine components. Because the storage is shared, it is physically
accessible to all of the cluster nodes. You can see an example of shared storage
architecture in Figure 2.1.
31
Understanding Hyper-V in Windows Server 2012
Figure 2.1
Previous versions of Hyper-V required failover clusters to make use of shared storage.
Cluster planning
Before you begin constructing a failover cluster you will need to do some
planning. Obviously you will need to decide whether the cluster will
use shared storage, youll need to take into account a number of other
considerations,including:
Node names Just as the cluster requires a cluster name, each cluster
node requires a unique computer name. Although Windows Server 2012
assigns computer names automatically, it is highly recommended that you
assign computer names that are more descriptive. Doing so makes it easier
tofigure out which node you are working on. The cluster nodes used in
theexamples in this chapter will be named Lab1, Lab2 and Lab3.
32
Understanding Hyper-V in Windows Server 2012
Number of nodes You also need to decide how many nodes touse
in your cluster. In this chapter you will be building a Majority Node Set
Cluster. It is best to use an odd number of cluster nodes whenever possible
because a Majority Node Set Cluster requires half of the nodes plus one
to remain online during a failure in order for the cluster to retain quorum.
It is technically possible to build a failover cluster out of two cluster nodes
(plus a file share witness), but it's recommended that you always use at
least three cluster nodes. Your cluster can contain as many as 63 nodes.
Of course, most clusters use far fewer than 63 nodes, and you always have
the option of adding additional cluster nodes later until the maximum
number of nodes has been reached.
33
Understanding Hyper-V in Windows Server 2012
You must install the Failover Clustering feature onto each of the cluster nodes.
6. When the wizard displays the list of server roles, click Next.
7. Select Failover Clustering from the list of features (Figure 2.3). If the wizard
prompts you to install additional features, click the Add Features button.
34
Understanding Hyper-V in Windows Server 2012
Figure 2.3
8. Click Next.
9. Click Install.
10. When the installation process completes, click Close.
35
Understanding Hyper-V in Windows Server 2012
Figure 2.4
You should specify all of the nodes that you want to include in the cluster.
36
Understanding Hyper-V in Windows Server 2012
6. Click Next.
7. You should now see a message indicating that the cluster has not yet been
validated. Choose the option to run the validation tests andclick Next
(Figure2.6). Windows will launch the Validate aClusterWizard.
Figure 2.6
You must validate the cluster before you can create it.
37
Understanding Hyper-V in Windows Server 2012
Figure 2.7
Review the validation report and check for any errors or warnings.
12. When prompted, enter a name for the cluster and assign an IP address
tothe cluster (Figure 2.8). The name and IP address that you use should be
unique and will be used to identify the cluster as a whole.
Figure 2.8
You must assign a unique name and static IP address to the cluster.
38
Understanding Hyper-V in Windows Server 2012
Choose the server on which you want to deploy the Hyper-V role.
39
Understanding Hyper-V in Windows Server 2012
6. Select the Hyper-V option from the list of roles (Figure 2.10).
Figure 2.10
7. If you are prompted to add additional features, click the Add Features
button.
8. Click Next.
9. Click Next.
10. Click Next.
11. Select the network adapters that you want to connect to the virtual
switch (Figure 2.11). You can select multiple network adapters, but as
abest practice you should reserve a network adapter for management
traffic andreserve an adapter for cluster communications (such as cluster
heartbeats and live migration traffic).
40
Understanding Hyper-V in Windows Server 2012
Figure 2.11
Select the network adapters that you want to connect to the Hyper-V virtual switch.
41
Understanding Hyper-V in Windows Server 2012
Navigate through the Failover Cluster Manager to Failover Cluster Manager | <your cluster
name> | Roles.
42
Understanding Hyper-V in Windows Server 2012
Figure 2.14
7. Select the virtual machines that you wish to make fault tolerant and click
Next (Figure2.15).
Figure 2.15
Select the virtual machines that you wish to make fault tolerant and click Next.
43
Understanding Hyper-V in Windows Server 2012
8. Verify the information displayed on the confirmation screen and click Next.
9. When the process completes you should see a message confirming that
high availability was successfully configured. Click the View Report button
to examine the report. Click Finish.
After the virtual machines become fault tolerant, you should see them listed
in the Failover Cluster Managers Roles container (Figure 2.16). Likewise,
theHyper-V Manager should list the virtual machine as being clustered
(Figure2.17).
Figure 2.16
The virtual machine should now be listed in the Failover Cluster Manager.
Figure 2.17
The Hyper-V Manager should list the virtual machine as being clustered.
44
Understanding Hyper-V in Windows Server 2012
45
Understanding Hyper-V in Windows Server 2012
Figure 2.18
8. Click Next.
9. Click Install.
10. When the installation process completes, click Close.
46
Understanding Hyper-V in Windows Server 2012
Figure 2.19
Specify the names of the servers that will make up the cluster.
6. Click Next.
7. You should now see a message indicating that the cluster has not yet
been validated. Choose the option to run the validation tests andclick
Next (Figure2.20). This will cause Windows to launch the Validate
aClusterWizard.
Figure 2.20
47
Understanding Hyper-V in Windows Server 2012
48
Understanding Hyper-V in Windows Server 2012
Figure 2.22
12. When prompted, enter a name for the cluster and assign an IP address
tothe cluster (Figure 2.23). The name and IP address that you use should
be unique and will be used to identify the cluster as a whole.
Figure 2.23
49
Understanding Hyper-V in Windows Server 2012
Shared storage
In the past if you wanted to use failover clustering with Hyper-V, you had to
make use of shared storage in the form of a Cluster Shared Volume. Although
Hyper-V 3.0 does not require a Cluster Shared Volume for clustering, shared
storage is still the preferred method for building a failover cluster.
As has always been the case, you can create a Cluster Shared Volume on
virtually any iSCSI or Fibre Channel accessible storage device. This can include
a SAN, a physical NAS appliance or even a server that is configured to act as
a shared storage device. The actual method you use to provision the shared
storage varies depending on the physical hardware you are using.
For the sake of demonstration, this example will use a Windows Server to
host the shared storage and will connect to this server using iSCSI. This server
contains four physical hard disks. The first hard disk is a 250-GB disk that
contains the Windows Server 2012 operating system files. The remaining
three hard disks are each 500 GB in size and will be configured to act as
aRAID 5 array. Keep in mind that this configuration is only being used for
demonstration purposes. Real-world organizations typically use larger arrays
and those arrays are often configured as RAID 6 or as RAID 10, because
50
Understanding Hyper-V in Windows Server 2012
The Disk Management Console lists all of the servers physical disks.
51
Understanding Hyper-V in Windows Server 2012
2. Right-click on one of the empty disks and choose the New RAID 5 volume
command from the right-click menu (Figure 2.26). Windows will launch
theNew RAID 5 Volume Wizard.
Figure 2.26
52
Understanding Hyper-V in Windows Server 2012
5. Click Next.
6. Select the drive letter that you wish to assign to the volume that you are
creating (Figure 2.28).
Figure 2.28
7. Click Next.
8. On the following screen choose the file system that you wish to use on the
new volume and decide whether to perform a quick format (Figure 2.29).
Figure 2.29
53
Understanding Hyper-V in Windows Server 2012
9. Click Next.
10. Click Finish.
11. A warning message tells you that the operation will convert the basic disks
to dynamic disks (Figure 2.30). Click Yes tocontinue.
Figure 2.30
12. After a brief delay Windows will format and synchronize the new volume.
Depending on the size of the disks that you are using, the synchronization
process can take a considerable amount of time to complete.
13. When the synchronization process completes, the new volume should be
displayed as Healthy (Figure 2.31).
Figure 2.31
54
Understanding Hyper-V in Windows Server 2012
55
Understanding Hyper-V in Windows Server 2012
Figure 2.33
The Primordial pool is created by default, but you will have to manually create all other
storage pools.
5. Choose the New Storage Pool option from the Task list.
6. When the New Storage Pool Wizard begins, click Next to bypass
thewizards Welcome screen.
7. Enter a name and an optional description of the storage pool that you
arecreating.
8. Click Next.
9. Choose the disks that you wish to include within the storage pool
(Figure2.34).
Figure 2.34
Choose the disks that you wish to include in the storage pool.
56
Understanding Hyper-V in Windows Server 2012
10. Use the Allocation drop-down for each disk to control whether the disk
should be allocated as a data store, a hot spare, or a manual allocation
(Figure 2.35).
Figure 2.35
57
Understanding Hyper-V in Windows Server 2012
You should now see the storage pool listed in the console along with
thephysical disks that make up the storage pool (Figure 2.37).
Figure 2.37
58
Understanding Hyper-V in Windows Server 2012
Figure 2.38
Choose the method Windows will use to protect your virtual disk.
59
Understanding Hyper-V in Windows Server 2012
9. Click Next.
10. Choose whether you want to thinly provision the Virtual Hard Disk or
create a disk of a fixed size (Figure 2.40). Fixed size provisioning delivers
better performance, but thin provisioning is more flexible andmakes more
efficient use of storage space.
Figure 2.40
11. Enter the size of the Virtual Hard Disk that you want to create (Figure 2.41).
60
Understanding Hyper-V in Windows Server 2012
Figure 2.41
61
Understanding Hyper-V in Windows Server 2012
Figure 2.42
62
Understanding Hyper-V in Windows Server 2012
Figure 2.43
63
Understanding Hyper-V in Windows Server 2012
Figure 2.44
5. Click Next.
6. Verify that the server that will host the Cluster Shared Volume is selected
(Figure 2.45).
Figure 2.45
Make sure that the server that will host the iSCSI target is selected.
64
Understanding Hyper-V in Windows Server 2012
7. Click Next.
8. On the Select Server Roles screen, verify that the File and Storage
Services role is installed. This role should be installed by default.
9. Expand the File and Storage Services container.
10. Expand the File and iSCSI Services container (Figure 2.46).
11. Select the iSCSI Target Server option and the iSCSI Target Storage
Provider option. If you are prompted to add additional features to support
those services, click the Add Features button.
Figure 2.46
Select the iSCSI Target Software and the iSCSI Target Storage Provider components.
65
Understanding Hyper-V in Windows Server 2012
Figure 2.47
Click the To Create an iSCSI Virtual Disk, Start the New iSCSI Virtual Disk Wizard link.
66
Understanding Hyper-V in Windows Server 2012
5. When the New iSCSI Virtual Disk Wizard begins, select your storage pool
and the volume that you just created (Figure 2.49).
Figure 2.49
6. Click Next.
7. Specify a name and an optional description for the iSCSI virtual disk
andclick Next.
8. Specify a size for the iSCSI virtual disk and click Next.
9. Choose the New iSCSI Target option and click Next.
10. Enter a name and an optional description for the iSCSI target and click
Next.
11. Add the names of the iSCSI initiators that will access the target. Populate
the dialog box with the IQN names from the iSCSI initiators on all of your
cluster nodes (Figure 2.50).
67
Understanding Hyper-V in Windows Server 2012
Figure 2.50
12. Once all of the cluster nodes have been added to the list, click Next.
13. Although not technically required, authentication is important for iSCSI
connectivity. Otherwise someone could easily spoof an IQN and gain
access to your iSCSI target. The wizard gives you a choice of enabling
CHAP or reverse CHAP authentication. As a best practice, you should
enable CHAP and provide a strong name and password (Figure 2.51).
Please note that your password must be at least 12 characters in length.
68
Understanding Hyper-V in Windows Server 2012
Figure 2.51
69
Understanding Hyper-V in Windows Server 2012
70
Understanding Hyper-V in Windows Server 2012
7. You should now be returned to the main initiator screen with the Targets
tab selected (Figure 2.54).
Figure 2.54
71
Understanding Hyper-V in Windows Server 2012
Figure 2.55
You must add the target to the list of favorite targets and enable multi-path.
10. Select the Enable Multi-Path check box. This is a critical step because
you wont be able to create a Cluster Shared Volume unless this option
isselected.
11. Click the Advanced button.
12. When the Advanced Settings dialog box launches, select theEnable
CHAP Log On check box (Figure 2.56).
Figure 2.56
You must choose the Enable CHAP Log On option and enter your CHAP credentials.
72
Understanding Hyper-V in Windows Server 2012
13. Enter the name that you specified earlier. You should enter the CHAP
password into the Target Secret field.
14. Click OK.
15. Click OK.
16. When you are returned to the Targets tab, the iSCSI Target should be
listed as Connected.
17. Click OK to close the iSCSI Initiator Properties sheet.
18. Repeat this procedure on the remaining cluster nodes so that each cluster
node has iSCSI connectivity to the target.
4. Right-click on the disk associated with the iSCSI target and choose
theInitialize Disk command from the right-click menu.
5. When prompted, select the type of partition that you wish to use with
thedisk (Figure 2.58) and click OK.
73
Understanding Hyper-V in Windows Server 2012
Figure 2.58
Select the type of partition that you wish to use for your Cluster Shared Volume and click OK.
Navigate through the Failover Cluster Manager to Failover Cluster Manager | <your cluster
name> | Storage | Disks.
11. Click the Add Disk link, found in the Actions pane.
12. The Failover Cluster Manager should automatically recognize your iSCSI
Target as a disk that can be added to the cluster (Figure 2.60). Verify that
the disk is selected and click OK.
74
Understanding Hyper-V in Windows Server 2012
Figure 2.60
13. The Failover Cluster Manager should list the disk as being available to
thecluster and show the disk status as Online (Figure 2.61). It is worth
noting that it can occasionally take a minute or two for the disk status to
be updated.
Figure 2.61
The Cluster Shared Volume should be listed within the Failover Cluster Manager.
14. With the cluster disk selected, click Add to Cluster Shared Volumes.
75
Understanding Hyper-V in Windows Server 2012
3. When the Add Roles and Features wizard launches, click Next to bypass
thewizards Welcome screen.
4. Make sure that the Role-Based or Feature-Based Installation option is
selected and click Next.
5. Select the server on which you want to deploy the Hyper-V role and click
Next.
6. Select the Hyper-V option from the list of roles.
7. If you are prompted to add additional features, click the Add Features
button.
8. Click Next.
9. Click Next.
10. Click Next.
11. Select the network adapters that you want to connect to the virtual switch
(Figure 2.62). You can select multiple network adapters, but as a best
practice you should reserve a network adapter for management traffic
andyou should reserve an adapter for cluster communications (such as
cluster heartbeats and live migration traffic).
Figure 2.62
76
Understanding Hyper-V in Windows Server 2012
Figure 2.63
77
Understanding Hyper-V in Windows Server 2012
As you may recall, you created a volume on the iSCSI target, but did not
assign adrive letter to it. You can access the Cluster Shared Volume at C:\
ClusterStorage\<your volume name>. Anything that you save to this path will
reside on the Cluster Shared Volume (the iSCSI target) rather than on the local
C: drive.
Simply storing the virtual machines on the Cluster Shared Volume is not
enough (Figure 2.64). As you can see in the figure, three virtual machines have
been created, and each of these virtual machines resides on the Cluster Shared
Volume. If you look at the lower middle pane in the next figure, however, you
will notice that the Hyper-V Manager indicates that the virtual machine is not
clustered (Figure 2.65).
Figure 2.64
78
Understanding Hyper-V in Windows Server 2012
Figure 2.65
Even with the virtual machines residing on the Cluster Shared Volume, the virtual machines
are not considered to be fault tolerant.
To make the virtual machine fault tolerant you must designate it as such
through the Failover Cluster Manager. To do so, follow these steps:
1. Open the Server Manager.
2. Choose the Failover Cluster Manager from the list of tools.
3. When the Failover Cluster Manager opens, navigate through the
console tree to Failover Cluster Manager | <your cluster name> | Roles
(Figure2.66).
Figure 2.66
Navigate through the Failover Cluster Manager to Failover Cluster Manager | <your cluster
name> | Roles.
79
Understanding Hyper-V in Windows Server 2012
7. Select the virtual machines that you wish to make fault tolerant and click
Next (Figure2.68).
80
Understanding Hyper-V in Windows Server 2012
Figure 2.68
Select the virtual machines that you wish to make fault tolerant.
81
Understanding Hyper-V in Windows Server 2012
After the virtual machines become fault tolerant, you should see them listed
in the Failover Cluster Managers Roles container (Figure 2.70). Likewise,
theHyper-V Manager should list the virtual machine as being clustered
(Figure2.71).
Figure 2.70
82
Understanding Hyper-V in Windows Server 2012
Figure 2.71
83
Understanding Hyper-V in Windows Server 2012
Chapter 3
Migrations
In the previous chapter, you spent a lot of time building
failover clusters and making virtual machines fault tolerant.
However, building the cluster is really just thebeginning.
It is equally important to know how to verify that
your failover cluster is working properly. As aHyper-V
administrator, you will also need to know how to move
virtual machines around both within and outside of
thecluster. This chapter discusses all of these tasks.
84
Understanding Hyper-V in Windows Server 2012
85
Understanding Hyper-V in Windows Server 2012
Figure 3.1
You can select the destination node manually, or you can let Hyper-V pick the best
nodeautomatically.
5. Choose the cluster node to which you want to live migrate the virtual
machine (Figure 3.2).
Figure 3.2
Select the cluster node to which you want to live migrate the virtual machine.
86
Understanding Hyper-V in Windows Server 2012
6. Click OK.
7. You can monitor the live migration process through the Failover Cluster
Manager (Figure 3.3).
Figure 3.3
The Failover Cluster Manager displays the progress of the live migration.
8. When the live migration completes, the Failover Cluster Manager should
report the virtual machine as running on the cluster node that you have
selected (as shown in the Owner Node column) (Figure 3.4).
Figure 3.4
The Owner Node column confirms that the virtual machine has been moved to a different
cluster node.
87
Understanding Hyper-V in Windows Server 2012
Figure 3.5
Right-click on the listing for the host server and select the Hyper-V Settings command from
the right-click menu.
3. When the Hyper-V Settings dialog box launches, select the Live
Migrations option (Figure 3.6).
Figure 3.6
88
Understanding Hyper-V in Windows Server 2012
4. Select the Enable Incoming and Outgoing Live Migrations check box
(Figure 3.7).
Figure 3.7
89
Understanding Hyper-V in Windows Server 2012
Figure 3.8
You will receive an error message if the CPUs on the source and destination hosts are
toodissimilar.
The solution to this problem is to enable CPU compatibility. You can accomplish
this by following these steps:
1. Open the Hyper-V Manager.
2. Shut down the virtual machine.
3. Right-click on the virtual machine and choose the Settings command from
the right-click menu.
4. Expand the Processor container in the resulting dialog box.
5. Select the Compatibility container.
6. Select the checkbox for Migrate to a Physical Computer with a Different
Processor Version (Figure 3.9).
7. Click OK.
8. Restart the virtual machine.
9. Attempt the live migration.
90
Understanding Hyper-V in Windows Server 2012
Figure 3.9
You can overcome some live migration issues by enabling the processor compatibility feature.
It is worth noting that enabling the CPU compatibility feature does not allow
you to move virtual machines between hosts with different CPU architectures
(e.g., moving from a host with an Intel processor to a host with an AMD
processor). Furthermore, enabling CPU compatibility might impact thevirtual
machines performance because the feature works by disabling the virtual
machines access to some of the more advanced CPU features such as
Misaligned SSE or POPCNT.
91
Understanding Hyper-V in Windows Server 2012
92
Understanding Hyper-V in Windows Server 2012
Figure 3.10
Right-click on the virtual machine and select the Remove command from
therightclickmenu.
6. When you see the prompt asking if you want to remove the virtual
machine, click Yes (Figure 3.11).
Figure 3.11
Confirm that you want to remove the virtual machine from the cluster.
93
Understanding Hyper-V in Windows Server 2012
Figure 3.12
Make sure that the VM is still running and that it is no longer clustered.
10. Right-click on the virtual machine and choose the Move command from
the right-click menu.
11. When the Move Wizard starts, click Next to bypass the wizards
Welcomescreen.
12. Choose the Move the Virtual Machine option and click Next (Figure 3.13).
94
Understanding Hyper-V in Windows Server 2012
Figure 3.13
13. When prompted, enter the name of the destination host (Figure 3.14).
Figure 3.14
95
Understanding Hyper-V in Windows Server 2012
Choose the option to move the virtual machine by selecting where to move each item.
96
Understanding Hyper-V in Windows Server 2012
Figure 3.16
97
Understanding Hyper-V in Windows Server 2012
3. When the Move Wizard opens, click Next to bypass the Welcome screen.
4. On the following screen, select the Move the Virtual Machine option and
click Next (Figure 3.17).
Figure 3.17
5. When prompted, enter the name of one of the cluster nodes (Figure 3.18).
Figure 3.18
6. Click Next.
7. Choose the Move the Virtual Machines Data to a Single Location option
(Figure 3.19).
Figure 3.19
8. Click Next.
9. Switch to the specified cluster node, open Windows Explorer and navigate
to C:\ClusterStorage\<volume name> (Figure 3.20).
99
Understanding Hyper-V in Windows Server 2012
Figure 3.20
10. Create a folder matching the name of the virtual machine that is
tobemigrated.
11. Switch back to the standalone host server where the virtual machine
currently resides.
12. Enter C:\ClusterStorage\<volume name>\<virtual machine name> as
thedestination location folder (Figure 3.21).
Figure 3.21
100
Understanding Hyper-V in Windows Server 2012
13. Verify that the destination folder has sufficient free disk space. Theamount
of disk space required is listed in the Source Location portion of
thewizards current screen.
14. Click Next.
15. If the cluster node does not contain a virtual switch with a name matching
the virtual switch that is currently in use, you will be asked to specify
avirtual switch (Figure 3.22). Make your selection andclickNext.
Figure 3.22
Specify the virtual switch that the virtual machine will use after the migration.
101
Understanding Hyper-V in Windows Server 2012
Figure 3.23
102
Understanding Hyper-V in Windows Server 2012
Figure 3.24
Select the Virtual Machine option from the list of high availability roles.
25. Select the recently migrated virtual machine from the list of virtual
machines and click Next (Figure 3.25).
Figure 3.25
Select the virtual machine that you want to make highly available.
103
Understanding Hyper-V in Windows Server 2012
26. Verify that the correct virtual machine is listed on the summary screen
andclick Next.
27. Verify that the virtual machine was made highly available (Figure 3.26).
28. Click Finish.
Figure 3.26
You can use the report to verify the success of the operation.
104
Understanding Hyper-V in Windows Server 2012
Figure 3.27
Select the virtual machine that you want to move to another cluster.
5. Right-click on the virtual machine and select the Remove command from
the right-click menu.
6. When you see the prompt asking if you want to remove the virtual
machine, click Yes (Figure 3.28).
Figure 3.28
Make sure that the VM is still running and that it has been removed from the cluster.
105
Understanding Hyper-V in Windows Server 2012
10. Right-click on the virtual machine and choose the Move command from
the right-click menu.
11. When the Move Wizard launches, click Next to bypass the wizards
Welcomescreen.
12. Choose the option to Move the Virtual Machine (Figure 3.30)
andclickNext.
Figure 3.30
106
Understanding Hyper-V in Windows Server 2012
Figure 3.31
107
Understanding Hyper-V in Windows Server 2012
Figure 3.32
Enter the path where the virtual machine should be stored on the destination cluster.
22. Verify that the destination folder has sufficient free disk space. Theamount
of disk space required is listed in the Source Location portion of
thewizards current screen.
23. Click Next.
24. If the cluster node does not contain a virtual switch with a name matching
the virtual switch that is currently in use, you will be asked to specify
avirtual switch. Make your selection and click Next.
25. Verify the summary information and click Finish.
26. When the migration process completes, go to the destination cluster node
and verify that the virtual machine is running.
27. Switch to the destination cluster node and verify that the virtual machine is
present and running.
28. Open the Server Manager.
29. Choose the Failover Cluster Manager option from the Tools menu.
30. Navigate through the Failover Cluster Manager to Failover Cluster
Manager | <your cluster> | Roles.
31. Click on the Configure Roles link, found in the Actions pane.
32. When the High Availability Wizard launches, click Next to bypass
theWelcome screen.
33. Select the Virtual Machine option and click Next (Figure 3.33).
108
Understanding Hyper-V in Windows Server 2012
Figure 3.33
Select the Virtual Machine option from the list of roles that can be configured for
highavailability.
34. Select the recently migrated virtual machine from the list of virtual
machines and click Next.
35. Verify that the correct virtual machine is listed on the summary screen
andclick Next.
36. Verify that the virtual machine was made highly available.
37. Click Finish.
38. The virtual machine should now be displayed as a clustered resource
within the Failover Cluster Manager (Figure 3.34).
Figure 3.34
The virtual machine should be displayed within the Failover Cluster Manager.
109
Understanding Hyper-V in Windows Server 2012
Right-click on a virtual machine and choose the Move | Virtual Machine Storage commands
from the right-click menu.
110
Understanding Hyper-V in Windows Server 2012
Right-click in the Cluster Storage section and choose the Add Share option.
6. When the Add a Network Share dialog box launches, enter the UNC share
name (\\servername\sharename) for the destination storage and click OK
(Figure3.37).
Figure 3.37
7. Confirm that the Move Virtual Machine Storage dialog box lists
thespecified network share in the Shares section (Figure 3.38).
111
Understanding Hyper-V in Windows Server 2012
Figure 3.38
8. Drag the virtual machine from the top section of the dialog box to
thelisting for the share that you have specified. The dialog box should
update to display the items that will be moved (Figure 3.39).
Figure 3.39
You should see the virtual machine components that are about to be migrated.
112
Understanding Hyper-V in Windows Server 2012
The Failover Cluster Manager should confirm that virtual machine migration has begun.
Right-click on a VM and choose the Move command from the right-click menu.
113
Understanding Hyper-V in Windows Server 2012
3. When the Move wizard launches, click Next to bypass the wizards
Welcomescreen.
4. Choose the option to move the virtual machines storage, andclick Next
(Figure 3.42).
Figure 3.42
5. Choose the option to Move All of the Virtual Machines Data to a Single
Location (Figure 3.43).
114
Understanding Hyper-V in Windows Server 2012
Figure 3.43
Choose the option to move all of the virtual machines data to a single location.
6. Click Next.
7. Specify the folder to which you want to move the virtual machine
(Figure3.44). Pay attention to the Current Location section within
thewizards current screen. This section tells you how much physical disk
space the virtual machine is currently consuming. You must verify that
there is sufficient disk space in the new location.
115
Understanding Hyper-V in Windows Server 2012
Figure 3.44
Specify the path to which you want to move the virtual machine.
8. Click Next.
9. Verify the information shown on the Summary screen.
10. Click Finish.
116
Understanding Hyper-V in Windows Server 2012
Figure 3.45
Choose the option to move the virtual machines data to different locations.
6. Click Next.
7. Choose the virtual machine components that you want to move
(Figure3.46) and click Next.
Figure 3.46
117
Understanding Hyper-V in Windows Server 2012
8. If you have chosen to move the Virtual Hard Disk, you will be prompted to
enter a new location for it (Figure 3.47). Enter the path to theVirtual Hard
Disks new location and click Next.
Figure 3.47
9. If you have chosen to move the virtual machines configuration, you will be
prompted to enter a path to the new location (Figure 3.48). Enter apath to
use for the virtual machines configuration and click Next.
118
Understanding Hyper-V in Windows Server 2012
Figure 3.48
10. If you have chosen to move the virtual machine snapshots, you will
be prompted to specify a path to the new location. Enter a path
andclickNext.
11. If you have chosen to move the Smart Paging files, you will be prompted
to enter a new location for them (Figure 3.49). Enter a path for the smart
paging files and click Next.
119
Understanding Hyper-V in Windows Server 2012
Figure 3.49
120
Understanding Hyper-V in Windows Server 2012
Figure 3.50
Choose the option to move only the virtual machines Virtual Hard Disks.
6. Click Next.
7. Select the Virtual Hard Disks that you want to move (Figure 3.51)
andclickNext.
Figure 3.51
121
Understanding Hyper-V in Windows Server 2012
8. Specify the location to which you wish to move the Virtual Hard Disks
andclick Next (Figure 3.52).
9. Verify the information on the summary screen andclickFinish.
Figure 3.52
Enter the path where the virtual hard disk should be stored.
122
Understanding Hyper-V in Windows Server 2012
Chapter 4
Managing Virtual
Machine Failover
The previous chapters show you how to build clustered
Hyper-V deployments and how to migrate virtual
machines within those environments. However, facilitating
live migrations is only part of a Hyper-V clusters job.
Acluster also has to keep virtual machines running, even
if the server on which a virtual machine is hosted were
tofail.
This chapter discusses various aspects of failover planning.
In this chapter you will learn about failover testing,
antiaffinity rules and virtual machine prioritization.
123
Understanding Hyper-V in Windows Server 2012
Failover testing
As you have no doubt seen in the previous chapters, there is a lot of work
that goes into building a Hyper-V cluster. However, none of the hard work
andexpense means very much if your cluster fails to keep your virtual
machines running when a hardware failure occurs. Of course you probably
dont want to wait for a disaster to happen in order to find out if your cluster
isworking or not. Its better to test the cluster ahead of time.
Failover cluster testing can be tricky in a production environment because
you dont want to jeopardize your production virtual machines in the testing
process. And its never a good idea to test your clustering solution by walking
through the datacenter and randomly yanking power cords out of clustered
hosts. Even though this type of testing makes for an amusing story, it is hardly
a recommended method.
Microsoft gives you a few different methods of testing failover within your
cluster. However, all of these tests tend to focus on the cluster at a high level.
Microsoft does not provide a method for testing the failover of an individual
virtual machine.
Validation testing
The first type of testing that you can perform is a cluster validation test. If this
sounds familiar, it is probably because you performed a validation test when
you were preparing to build the failover cluster.
Even though you may think of a validation test as a tool to use in preparation
for building a cluster, you can perform these types of tests against a cluster
that has already been established. The reason why this might be helpful
is because cluster configurations tend to change over time and validation
testing will help you spot any configuration problems that might exist within
yourcluster.
124
Understanding Hyper-V in Windows Server 2012
You can perform validation testing either through the Failover Cluster Manager
or through PowerShell. To perform validation testing using the Failover Cluster
Manager, follow these steps:
1. Open the Server Manager.
2. Select the Failover Cluster Manager command from the Tools menu.
3. When the Failover Cluster Manager opens, select the listing for your
cluster within the console tree.
4. Click on the Validate Cluster link, found in the Actions pane (Figure 4.1) .
Figure 4.1
Choose the option to run only the tests that you select.
125
Understanding Hyper-V in Windows Server 2012
7. Click Next.
8. On the following screen, select the tests that you want to run (Figure 4.3).
You can select entire categories of tests (such as Inventory, Network, or
System Configuration), or you can expand a category and select individual
tests within that category.
Figure 4.3
9. Click Next.
10. The following screen displays your cluster disk (assuming that your cluster
uses a Cluster Shared Volume) and indicates that you can select the cluster
disk if you want to include it in the validation testing (Figure 4.4). However,
you should only run the tests against your cluster disk if the Cluster
Shared Volume has been stopped. Otherwise, the testing can cause virtual
machines to fail.
126
Understanding Hyper-V in Windows Server 2012
Figure 4.4
Do not select the cluster disk if your Cluster Shared Volume is in use!
The Test-Cluster cmdlet can be used for comprehensive cluster validation testing.
When you first enter the Test-Cluster cmdlet, PowerShell may appear to
lock up. After several seconds you should see the tests begin, as shown in
Figure4.6.
When the validation testing completes, you will see a message that refers to
a validation report (Figure 4.7). The validation report file is located in the C:\
Windows\Cluster\Reports folder. You can open the validation reports using
Internet Explorer, as shown in Figure 4.8.
Figure 4.7
128
Understanding Hyper-V in Windows Server 2012
Figure 4.8
Keep in mind that the validation report shown in the figure above was based
on a comprehensive set of cluster tests. It is possible to exercise a high degree
of granular control over the testing process. Using PowerShell, you can run
specific validation tests, exclude certain validation tests and direct the testing
process to specific cluster nodes.
The trick to using PowerShell to control the validation tests is to retrieve a list
of the test names. Once you have a list of the test names (as referenced by
PowerShell) you can begin to include or exclude specific tests. To get a list of all
of the test names, enter the following command (Figure 4.9):
Test-Cluster List
129
Understanding Hyper-V in Windows Server 2012
Figure 4.9
Once you have a list of test names, it is easy to include or exclude individual
tests. For example, suppose that you want to perform all of the validation tests
except for those related to storage. You can do so by entering the following
command:
Test-Cluster Ignore Storage
Similarly, if you only want to run the system drivers test, you can enter
acommand like this one (Figure 4.10):
Test-Cluster Include List System Drivers
Figure 4.10
You can also use PowerShell to specify the cluster nodes to include in
thevalidation tests. For example, suppose that you want to run the validation
tests against nodes named Lab1, Lab2, and Lab3 (Figure 4.11). To do so, you
can use the following command:
Test-Cluster Node Lab1,Lab2,Lab3
130
Understanding Hyper-V in Windows Server 2012
Figure 4.11
131
Understanding Hyper-V in Windows Server 2012
Figure 4.12
Notice in the figure above that the last item on the list is Virtual Machine VM3.
This virtual machines name is VM3, but for the purpose of cluster resource
testing, the virtual machine must be referred to as Virtual Machine VM3. If
you want to see what would happen if the virtual machine fails, you can enter
thefollowing command (Figure 4.13):
Test-ClusterResourceFailure Virtual Machine VM3
Figure 4.13
If you look at the Failover Cluster Manager, you can see that the virtual
machine can actually go down as a result of the test (Figure 4.14). Running
thetest once against a virtual machine causes the virtual machine to go down
for a moment and then come back up. However, running the test twice usually
takes thevirtual machine completely offline until you right-click on the virtual
machine and choose the Start option from the right-click menu.
Figure 4.14
132
Understanding Hyper-V in Windows Server 2012
For the most part, cluster resource failure testing is limited to the items on
thelist of cluster resources (Figure 4.12). The big exception, however, is that you
can also test cluster disks. Suppose for example that you want to test thefailure
of a disk named Cluster Disk 1 (Figure 4.12). You can do so by entering the
following command:
Test-ClusterResourceFailure Name Cluster Disk 1
Figure 4.15
You can use the Test-ClusterResourceFailure cmdlet to test cluster disk failures.
Failover testing
The third type of testing you can do with regard to your cluster is failover
testing. Failover testing simulates the failure of an active cluster node and tests
the clusters ability to failover to another node in the cluster.
Unfortunately, Microsoft does not provide a mechanism for testing the failover
of an individual virtual machine. Instead, failover testing occurs at the cluster
level. To perform a failover test, follow these steps:
1. Open the Server Manager.
2. Choose the Failover Cluster Manager command from the Tools menu.
3. When the Failover Cluster Manager appears, navigate through the console
tree to Failover Cluster Manager | <your cluster> (Figure 4.16) .
133
Understanding Hyper-V in Windows Server 2012
Figure 4.16
4. Click on the More Actions link, found in the Actions pane and then click
on the Simulate Failure link (Figure 4.17).
Figure 4.17
134
Understanding Hyper-V in Windows Server 2012
You can watch the failover occur in the Cluster Core Resources pane.
Anti-affinity rules
In multi-tenant environments, it is sometimes necessary to configure certain
virtual machines so that they never reside on the same host server. For
example, if your organization were hosting virtual machines for both Coke
andPepsi, you would not want the two companies virtual machines to reside
on a common host server.
It is relatively easy to keep virtual machines separate from one another when
you initially create the virtual machines. However, virtual machines are anything
but static and the chances of a virtual machine remaining on the same Hyper-V
host for an indefinite period of time are slim.
If you have virtual machines that need to be kept separate, you can reduce
thechances of those virtual machines ever ending up on a common host by
using anti-affinity rules. Anti-affinity rules prevent virtual machines that must
remain separate from failing over to a common host.
Unfortunately, anti-affinity rules are not exactly easy to work with. These
rules can only be established through PowerShell, and the process is not
veryintuitive.
The key to understanding how the process works is to understand that
forevery clustered virtual machine, there is a corresponding cluster group.
Each cluster group uses the same name as the virtual machine for which
it was created. Anti-affinity rules are applied to cluster groups, not to
virtualmachines.
Like other types of objects in PowerShell, cluster groups have a number of
different properties (Figure 4.19). To see a list of the cluster group properties,
enter the following command:
Get-ClusterGroup <group name> | Select-Object *
135
Understanding Hyper-V in Windows Server 2012
Figure 4.19
As you look at the properties in the screen capture above, you will notice that
the third property from the bottom of the list is named AntiAffinityClassNames.
Creating an anti-affinity rule involves assigning a value to this property.
Normally you could modify this type of value by using a command like this:
Get-ClusterGroup <virtual machine name> | Set-ClusterGroup
AntiAffinityClassNames <value>
However, there is just one problem with the command shown abovethere
is no Set-ClusterGroup cmdlet. The fact that such a command does not exist
is asafety precautionif a Set-ClusterGroup cmdlet did exist, you could
potentially destroy a virtual machine if you used the cmdlet incorrectly.
Since you cant use Get-ClusterGroup and Set-ClusterGroup, you have to use
a completely different approach to modifying the AntiAffinityClassNames
property.
Unfortunately, Windows PowerShell does not contain the code for managing
the AntiAffinityClassNames property. However, you can download a PowerShell
module that makes it possible to directly manipulate this property. In case
you are not familiar with the concept of a PowerShell module, it is basically
acollection of PowerShell cmdlets that can be bolted on to the core cmdlet set.
You can download the PowerShell Module for Configuring AntiAffinityClassNames
in Failover Clustering at: http://gallery.technet.microsoft.com/PowerShell-
module-for-16242485. This module is designed for use with Windows Server
2008 R2, but it works with Windows Server 2012 as well.
The download consists of a ZIP file. You will need to download the ZIP file
andextract its contents to the servers hard disk. The path that you use is up to
you, but you will have to enter the full path into PowerShell, so it is beneficial
to use a relatively simple path. For demonstration purposes this example places
the extracted files into a folder named C:\Modules.
136
Understanding Hyper-V in Windows Server 2012
Once you have extracted the zip files contents, youll need to import
themodule into PowerShell. Note that importing a module is not a permanent
operation. The module only remains imported for as long as PowerShell is
open. If you need to use the module again at a later time, you will have to
import it again.
Before you can import the module, you will have to configure your servers
execution policy to allow PowerShell scripts to be run. The easiest way to do
this is to enter the following command:
Set-ExecutionPolicy Unrestricted
This command allows PowerShell to run any PowerShell script, regardless
of where it came from (Figure 4.20). Obviously, there are some security
implications associated with allowing unrestricted access to scripts, as
explained in the text shown below (Figure 4.20). If you are concerned about
security, you can set the execution policy back to Restricted when you finish
working with the AntiAffinityClassNames by using the Set-ExecutionPolicy
Restricted cmdlet.
Figure 4.20
You must configure the execution policy to allow PowerShell scripts to be run.
With that said, you can use the following command to import the module
(assuming that the module resides in C:\modules):
Import-Module C:\Modules\AntiAffinityClassNames
When you execute the command listed above, you will see several prompts
asking if you want to allow the script to run (Figure 4.21). You must run each of
these scripts in order to successfully import the module.
Figure 4.21
You must import the AntiAffinityClassNames module before you can use it.
137
Understanding Hyper-V in Windows Server 2012
Now that all of the necessary components are in place, you can begin working
with anti-affinity rules. The basic idea behind these rules is that certain servers
should never reside on the same hosts. You can specify these servers by
adding a value to the AntiAffinityClassNames parameter. Servers with the same
AntiAffinityClassNames parameter will not normally fail over to a common
host.
A more concrete example of how this works is a situation in which
anorganization has multiple virtualized domain controllers. You would never
want to be in a situation in which all of your domain controllers failed over
to the same host. That being the case, you could add the phrase Domain
Controller to each domain controllers AntiAffinityClassNames parameter
to indicate that each server that uses this tag is a domain controller and that
each domain controller should reside on a separate host. To be perfectly
clear, theDomain Controllers value is just an exampleyou can call your
antiaffinity values anything that you want.
Setting up anti-affinity rules in this manner does not guarantee that the virtual
machines will never be hosted on the same server. If the cluster is ever put
into a situation where there arent enough remaining cluster nodes to facilitate
therequirements of the anti-affinity rules, Windows will place the virtual
machines wherever it can. The assumption is that it is more important to keep
the virtual machines running than it is to keep them separated.
Now you can configure anti-affinity rules by using the Set-AntiAffinityClassNames
cmdlet. This cmdlet requires you to specify the name of the cluster, the cluster
group to which the rule should apply (the cluster group name is the same as
the virtual machine name), and the value that you want to assign. Suppose, for
example, that your cluster is named HyperVCluster and that you want to assign
an AntiAffinityClassNames value of Domain Controller to a virtual machine
named VM3. To do so, use the following command:
Set-AntiAffinityClassNames Cluster HyperVCluster ClusterGroup VM3
Value Domain Controller
138
Understanding Hyper-V in Windows Server 2012
139
Understanding Hyper-V in Windows Server 2012
Unfortunately, there is no magic trick that you can use to make the cluster
node handle all of those virtual machines from the failed cluster node. Servers
only have so much memory and when all of that memory has been allocated,
theserver will be unable to host any additional virtual machines.
Because Windows cant expand a cluster nodes capacity so that it can handle
more virtual machines, Windows instead lets you prioritize virtual machines.
In any organization there are some virtual machines that are more important
than others. For example, your mail server is probably more important than
aredundant domain controller.
By prioritizing your virtual machines, you can make sure that the most
important virtual machines continue to function in a failover situation.
Windows will start the highest priority virtual machines first and lower priority
virtual machines in sequence until the server runs out of memory or other
resources.
Setting a virtual machines priority is easy. To do so, follow these steps:
1. Open the Server Manager.
2. Choose the Failover Cluster Manager command from the Tools menu.
3. When the Failover Cluster Manager starts, select the Roles container.
4. Right-click on the virtual machine that you want to prioritize and choose
the Change Startup Priority command from the right-click menu
(Figure4.25).
5. Specify the virtual machines priority.
Figure 4.25
As you look at the figure above, you will notice that the Failover Cluster
Manager has a Priority column that displays each virtual machines priority.
Every virtual machine has a default priority of Medium, but you can raise
orlower that priority based on the virtual machines importance.
140
Understanding Hyper-V in Windows Server 2012
Hyper-V allows you to specify a preferred host server for any clustered virtual machine.
Although Microsoft makes it easy to specify a preferred host, there are two
things that you should know about host server prioritization. First, you can
specify multiple preferred servers by selecting the checkboxes for each
preferred cluster node. Use the Up and Down buttons shown in the figure
above to arrange the list of cluster nodes based on your preferred priority.
Second, host prioritization is not guaranteed. If a virtual machines preferred
host is offline or lacks the capacity to host a virtual machine, the virtual
machine will be hosted on a cluster node other than the preferred node.
141
Understanding Hyper-V in Windows Server 2012
Failover rules
The Failover Cluster Service allows you to set some ground rules for theway
that virtual machines failover to other cluster nodes. These rules are all
controlled through a dialog box within the Failover Cluster Manager. To access
this dialog box, follow these steps:
1. Open the Server Manager.
2. Select the Failover Cluster Manager option from the Tools menu.
3. When the Failover Cluster Manager opens, select the Roles container.
4. Right-click on a clustered virtual machine.
5. Select the Properties command from the right-click menu.
6. When the virtual machines properties sheet appears, select the Failover
tab (Figure 4.27).
Figure 4.27
Note that the Failover tab is divided into two sections. The first section allows
you to define the maximum number of failovers that can occur within a given
period of time. The idea is that if a virtual machine fails over repeatedly, there
is probably a serious problem with that virtual machine or with the cluster
and it might be better to simply take the virtual machine offline and put it
into a failed state rather than allow it to keep failing over. By default, failures
are capped at two failures within a six-hour period, but you can adjust these
settings based on your needs.
142
Understanding Hyper-V in Windows Server 2012
The lower portion of the dialog box lets you control whether or not
thevirtual machine will be allowed to fail back to the server on which it was
originally hosted. By default, automatic failback is disabled. However, you
can enable automatic failback and configure it to happen immediately or on
ascheduledbasis.
In most cases it is best to leave automatic failback disabled. If a failover
occurred, a problem exists that caused the failover, and you dont want
your virtual machines automatically failing back to a cluster node that has
anunresolved problem.
143
Understanding Hyper-V in Windows Server 2012
Chapter 5
PowerShell
Management
In Windows Server 2008 and 2008 R2, Microsoft allowed
many aspects of the Windows operating system to be
managed through PowerShell. Because PowerShell was
relatively new, however, there were certain operating
system components (including Hyper-V) that could not
be managed through PowerShell. Microsoft eventually
released a PowerShell module for Hyper-V, but this
module had to be downloaded separately. Thankfully,
theWindows Server 2012 version of Hyper-V includes
native PowerShell management capabilities. It is the goal
of this chapter to familiarize you with the various ways
inwhich Hyper-V can be managed through PowerShell.
144
Understanding Hyper-V in Windows Server 2012
Syntax simplification
Before discussing PowerShell management for Hyper-V, there is some
good news. While developing Windows Server 2012, Microsoft realized that
nondevelopers often struggled with PowerShell. In spite of what themarketing
folks might say, the syntax for various PowerShell commands was often
complex and completely non-intuitive. Thankfully, Microsoft decided to simplify
the PowerShell syntaxespecially as it relates to the Where-Object and
ForEach-Object cmdlets.
To show you an example of the way that the syntax has been simplified,
imagine that you want to see a list of all of the processes that are running on
the local Hyper-V host server. Prior to Windows Server 2012, you would have
had to use this command:
Get-Process | ForEach {$_.Name}
This same simplification also applies to operations in which you use operators
to filter the result set. For example, prior to Windows Server 2012, to see a list
of all of the processes using more than 500 handles, you would have had to use
the following command:
Get-Process | where {$_.Handles gt 500}
145
Understanding Hyper-V in Windows Server 2012
Notice in the screen capture (Figure 5.1) that the PowerShell prompt changes
to reflect the name of the server that you are attached to.
Figure 5.1
You can use the Enter-PSSession cmdlet to establish a remote PowerShell session.
146
Understanding Hyper-V in Windows Server 2012
Figure 5.2
You can use the Invoke-Command cmdlet to remotely execute a PowerShell command.
Keep in mind that these are the simplest methods of establishing a remote
PowerShell session. Things can become more complex if you need to enter
analternative set of permissions or if you need to modify the execution
policy to allow scripts to be run. For example, the block of PowerShell listed
below is used to manage an Office 365 environment through PowerShell.
Although Office 365 is beyond the scope of this book, this example illustrates
the point that there are more complex methods of establishing remote
PowerShellconnectivity.
Set-ExecutionPolicy RemoteSigned
Import-Module MSOnline
$Cred = Get-Credential
$MySession = New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri https://ps.outlook.com/powershell -Credential $Cred
-Authentication Basic -AllowRedirection
Import-PSSession $MySession
147
Understanding Hyper-V in Windows Server 2012
Figure 5.3
The Get-VM cmdlet returns a list of the virtual machines that are present on the host.
Notice in Figure 5.3 that the Get-VM cmdlet returns virtual machine information
from the local server. Had we established a PowerShell session with a remote
server, virtual machine information from the remote server would have been
returned instead. If you need to perform a Get-VM query against a remote
server, however, it may not always be necessary to establish a session with the
server. Remote sessions are most useful when you need to redirect PowerShell
so that all operations are performed against the remote host instead of
the local host. If you simply need to retrieve a bit of information from the
remote host, you can often do so by using a standard PowerShell cmdlet and
appending the name of the remote server.
To see how this works, imagine that you want to see a list of the virtual
machines residing on a host named Prod1 (Figure 5.4). You can accomplish this
by entering the following command:
Get-VM ComputerName Prod1
Figure 5.4
You can get a list of the virtual machines that reside on a specific host.
Of course, the list of virtual machines that are running on a specific host could
potentially be really long. Often you might be more interested in viewing
the state of a specific virtual machine rather than seeing a list of every virtual
machine that exists on a host server. In this case, you can append a virtual
machine name directly to the end of the Get-VM cmdlet (Figure 5.5). For
example, to view the current state of a VM named Lab-DC you can enter
thiscommand:
Get-VM Lab-DC
Figure 5.5
148
Understanding Hyper-V in Windows Server 2012
Just as you can use the Get-VM cmdlet to retrieve basic information about
virtual machines, you can use the Get-VMHost cmdlet to access information
about host servers (Figure 5.6). Entering the Get-VMHost cmdlet by itself
returns the name of your host server along with its logical processor count,
memory capacity and whether or not the virtual machine is configured to allow
virtual machine migrations.
Figure 5.6
You can use the Get-VM cmdlet to retrieve virtual machine information.
149
Understanding Hyper-V in Windows Server 2012
One of the nice things about PowerShell is that it allows you to use attributes
and operators to filter a cmdlets output. Some of the commonly used
operators include:
Equal To -EQ
Or -OR
And -AND
Like -Like
Greater Than -GT
Less Than -LT
You can combine these operators with object attributes to retrieve very
granular information about your host servers and virtual machines.
One of the most basic examples of output filtering involves filtering virtual
machines by name. For example, entering the Get-VM cmdlet on the host Lab1
returns listings for a number of virtual machines. On this server the name of
each virtual machine reflects the virtual machines purpose. For example, virtual
machines starting with LAB15 are lab machines related to Microsofts wave 15
product release (Office 15, SharePoint 15, Exchange 15, etc.).
With this in mind, it might occasionally be necessary to get a list of the virtual
machines that are related to wave 15 testing. In this situation, the Like operator
could prove to be very handy. You can use the Like operator to list values that
are similar to a target value. For instance, you can list all of the virtual machines
that have names starting with Lab15 (Figure 5.9) by using the following cmdlet:
Get-VM | Where Name Like Lab15*
Figure 5.9
You can use filtering to narrow down the list of virtual machines.
Being able to filter virtual machines by name is nice, but this is not the only
type of filtering you can do. It is also possible to filter on things like a virtual
machines state. For instance, if you want to see which virtual machines are
currently powered off (Figure 5.10), you can use the following command:
Get-VM | Where State EQ Off
Figure 5.10
150
Understanding Hyper-V in Windows Server 2012
Obviously its handy to be able to see a list of the virtual machines that are
powered off, but remember that the command shown above only looks
atthecurrent host server. What if you wanted to see a list of the running virtual
machines across multiple hosts? To accomplish this, you would simply add
theComputerName switch and the names of the hosts that should be
included in the query (Figure 5.11). The command might look something
likethis:
Get-VM ComputerName Lab1,Lab2,Lab3,Prod1,Prod2 | Where State EQ
Running
Figure 5.11
A filtered output can contain data from multiple Hyper-V host servers.
This technique becomes most useful when you apply multiple filters together.
If you look at the previous screen capture you will notice that one clustered
virtual machine is running and another is not. If this were a production
environment with lots of virtual machines, it might be useful to compile a list of
the clustered virtual machines that were not running (Figure 5.13). You could do
this by entering the following command:
Get-ClusterGroup | Where GroupType EQ VirtualMachine | Get-VM | Where
State EQ Off
Figure 5.13
You can create a list of clustered virtual machines that are not currently running.
151
Understanding Hyper-V in Windows Server 2012
You can use PowerShell to determine which VMs are consuming excessive system resources.
152
Understanding Hyper-V in Windows Server 2012
Figure 5.15
This command displays all of the available attributes in list format. Pay
attention to the attribute names because you can use these names to
customize theoutput or to apply filters. Similarly you can view all of the
attributes that are available within the Get-VMHost cmdlet (Figure 5.16) by
entering thiscommand:
Get-VMHost | FL *
153
Understanding Hyper-V in Windows Server 2012
Figure 5.16
You can use the Get-VMHost cmdlet to retrieve host server information.
As you can see, there is a lot of information available both for virtual machines
and for host servers. But what can you do with all of this information?
Forstarters, you can control the output of the Get-VM or the Get-VMHost
cmdlets (Figure 5.17). For example, suppose that you want to see each virtual
machines name, the name of the host on which the virtual machine currently
resides andwhether or not the virtual machine is clustered. You can accomplish
this by entering the following command:
Get-VM | FT VMName, ComputerName, IsClustered
Figure 5.17
You can control the output of the Get-VM or the Get-VMHost cmdlets.
Of course, you output the values of any of the available attributes and you can
also use the various attributes with operators such as Like, -And, -GT, etc.
toachieve a filtered output.
It is worth noting that Microsoft provides a number of cmdlets that you can
use as shortcuts to retrieve very specific information about virtual machines.
Forexample, you can use the Get-VMMemory cmdlet to retrieve a virtual
machines memory configuration. Likewise, you can use the Get-VMProcessor
cmdlet to view a virtual machines virtual CPU configuration.
154
Understanding Hyper-V in Windows Server 2012
Reporting
In the previous section you learned how to modify the Get-VM
andtheGetVMHost cmdlets to achieve the desired output, but you can
actually take things a step further and use PowerShell as a reporting engine.
You can use PowerShell to create CSV, Text and even HTML files.
155
Understanding Hyper-V in Windows Server 2012
Figure 5.19
Often, it is necessary to use the Select-Object cmdlet to specify what data to include
inareport.
156
Understanding Hyper-V in Windows Server 2012
CSV files
CSV files are almost always created in table format. CSV files are useful
foroutputting large amounts of information in a format that can be read
by Microsoft Excel or imported into a database. You can create a CSV file by
appending the Export-CSV cmdlet to whatever command you are using. It
is worth noting, however, that you must manually specify the attributes to
include in the output. For example, to create a CSV file containing a listing of
your virtual machines, their state, the host, whether or not the virtual machine
is clustered, and the virtual machines uptime and status (Figure 5.21), you can
enter this command:
Get-VM | Select-Object VMName, State, ComputerName, IsClustered,
UpTime, Status | Export-CSV C:\Data\VMs.csv
Figure 5.21
Once created, you can open the CSV in Microsoft Excel (Figure 5.22).
Figure 5.22
Text files
The process of creating a text file is similar to that of creating a CSV file,
butPowerShell is a bit more forgiving when it comes to creating text files.
Youdont have to use the Select-Object cmdlet and can instead use FT or FL.
Rather than using the Export-CSV cmdlet, you will use the Out-File cmdlet.
Other than that, the commands are identical. For example, to write a list of
virtual machines to a text file (Figure 5.23), you can use this command:
Get-VM | FT VMName, State, ComputerName, IsClustered, UpTime, Status |
Out-File C:\Data\VMs.txt
157
Understanding Hyper-V in Windows Server 2012
Figure 5.23
Notice in Figure 5.23 that you can view the contents of the newly created
text file by entering the Type command, followed by the path and filename
of thetext file. Of course, you can also open the file in Notepad or any other
texteditor.
HTML reports
The process of creating an HTML report is similar to that of creating a text
fileboth use the Out-File cmdlet. However, to create an HTML report,
youneed to add the ConvertTo-HTML cmdlet. For example, to write a list of
your virtual machines to an HTML file, use this command:
Get-VM | Select-Object VMName, State, ComputerName, IsClustered,
UpTime, Status | ConvertTo-HTML | Out-File C:\Data\VMs.htm
Just for fun, you can modify this command so that it creates the report
andautomatically opens it in Internet Explorer (Figure 5.24). To do this,
append the Invoke-Expression cmdlet to the end of the command as shown
inthefollowing example:
Get-VM | Select-Object VMName, State, ComputerName, IsClustered,
UpTime, Status | ConvertTo-HTML | Out-File CL\Data\VMs.htm | Invoke-
Expression C:\Data\VMs.htm
Figure 5.24
As you can see, the process of writing data to an HTML report works pretty
well, but the report is very plain (Figure 5.25) and not very visually appealing.
To make your reports more visually interesting, you can create a style section
and incorporate it into the report.
158
Understanding Hyper-V in Windows Server 2012
Figure 5.25
The block of code below (Figure 5.26) creates a PowerShell variable named
$a and then adds an HTML style section to that variable. The actual report is
created as discussed earlier, but with a couple of differences. When it comes
time to issue the ConvertTo-HTML command, you insert the Head switch
and the $a variable. You also insert the Body tag and a header. The end result
is a much more attractive HTML report (Figure 5.27). This is how the code
iswritten:
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color:
black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-
color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-
color: black;background-color:PaleGoldenrod}"
$a = $a + "</style>"
Get-VM | Select-Object VMName, State, ComputerName, IsClustered,
UpTime, Status | ConvertTo-HTML -head $a -body "<H2>Virtual Machines</
H2>" | Out-File C:\Data\VMs.htm
Figure 5.26
159
Understanding Hyper-V in Windows Server 2012
Figure 5.27
With a little bit of imagination you can create scripts that produce color-coded
reports. For example, you can list virtual machines that are offline in red and list
online virtual machines in green.
You will see a warning message if a virtual machine cannot be shut down gracefully.
The Start-VM cmdlet starts the virtual machine. The only required parameter is
the name of the virtual machine that you want to start (Figure 5.29).
160
Understanding Hyper-V in Windows Server 2012
Figure 5.29
When you enter this command, you will see confirmation that the new virtual
machine was created. The new virtual machine should also be displayed in
theHyper-V Manager (Figure 5.31).
Figure 5.31
161
Understanding Hyper-V in Windows Server 2012
Keep in mind that you will almost always have to make modifications to a newly
created virtual machine before using it. When you create a virtual machine
using the method discussed above, it is allocated minimal hardware that is
almost never suitable for real world use. The hardware allocation includes:
512 MB of memory
DVD drive
No virtual hard disk
No network connection
One virtual processor
Fortunately, you can use PowerShell cmdlets to modify a new or an existing
virtual machine.
Memory
The resource that you will likely have to adjust more often than any other is
memory. You can adjust memory by using the Set-VMMemory cmdlet.
Start the process by entering the Get-VMMemory cmdlet, followed by
thename of the virtual machine (Figure 5.32). This causes PowerShell to display
the virtual machines current memory configuration.
Figure 5.32
You can use the Get-VMMemory cmdlet to see a virtual machines memory assignment.
162
Understanding Hyper-V in Windows Server 2012
Figure 5.33
You can use the Set-VMMemory cmdlet to allocate memory to a virtual machine.
This command sets the startup memory to 2 GB. You can verify the operations
success by using the Get-VMMemory cmdlet.
If you want to configure a virtual machine to use dynamic memory, things
become a bit more complicated. You still use the Set-VMMemory cmdlet,
butyou have to include a specification to enable dynamic memory. You will
also have to provide values for the minimum, startup and maximum memory.
You can optionally set a priority and a buffer value for the virtual machine as
well by using the following command:
Set-VMMemory <virtual machine name> -DynamicMemoryEnabled $True
MinimumBytes <minimum memory> -StartupBytes <startup memory>
-MaximumBytes <maximum memory> -Priority <priority> -Buffer
<buffervalue>
For example, suppose you want to configure the virtual machine PowerShellVM
to use a 1 GB of startup memory and you want to set the minimum memory
to 512 MB and the maximum memory to 2 GB. Lets also assume that you want
to set the priority to 80 and the buffer to 25 (Figure 5.34). You can do this with
thefollowing command:
Set-VMMemory PowerShellVM DynamicMemoryEnabled $True
MinimumBytes 512MB -StartupBytes 1GB MaximumBytes 2GB Priority 80
Buffer 25
Figure 5.34
You can also use the Set-VMMemory for configuring dynamic memory.
Now that you know how to allocate memory to a virtual machine, here are
a couple of shortcuts that you can use. Keep in mind that you can use these
shortcuts with any type of hardware allocation. The following example uses
only memory allocation.
163
Understanding Hyper-V in Windows Server 2012
When the operation has completed, you can verify its success by specifying all
three virtual machine names within the Get-VMMemory cmdlet. For example,
inthis situation you would enter:
Get-VMMemory NewVM1,NewVM2,NewVM3
Keep in mind that this is not the only way to allocate memory to multiple
virtual machines. You can also specify the virtual machines to which you want
to allocate memory using filtering. For example, you can create a filter based
on the virtual machines name or on the amount of memory that is currently
allocated to the virtual machine.
164
Understanding Hyper-V in Windows Server 2012
You can use the Get-VMNetworkAdapter cmdlet to access virtual network adapter
information for a virtual machine.
In many cases, you may find that although a network adapter has been
assigned to a virtual machine, you must connect that network adapter
toavirtual switch. Fortunately, this is relatively easy to do. While it is possible
to use a single command to attach a virtual network adapter to a virtual
switch, its better to use variables because the virtual network adapter name
andthevirtual switch name may be long. Using variables reduces the chances
of making a mistake by mistyping one of the names.
Therefore, the first step in the process is to retrieve the name of the virtual
machines virtual network adapter and assign this name to a variable named
$VMNic using the following command:
$VMNic = Get-VMNetworkAdapter VMName <virtual machine name>
The next step is to retrieve the name of the virtual switch by using
thefollowing command:
Get-VMSwitch | Select-Object Name
If you have multiple virtual switches, you can narrow down the results by
specifying the virtual switchs connectivity. For example, if you only want to use
an external virtual switch, you can use the following cmdlet:
Get-VMSwitch SwitchType External | Select-Object Name
Now you just need to connect the virtual network adapter to the virtual switch.
You should be able to do this by using the Connect-VMNetworkAdapter
cmdlet; however, PowerShell apparently doesnt allow you to add the virtual
switch name to a variable and use the variable to connect the virtual switch
toa virtual network adapter. Instead, you have to enter the virtual switch name
in long form. The command looks something like this:
Connect-VMNetworkAdapter VMNetworkAdapter $VMNic SwitchName
<virtual switch name>
165
Understanding Hyper-V in Windows Server 2012
As a more concrete example, for the virtual switch on a test server named
Intel(R) Gigabit CT Desktop Adapter #2 Virtual Switch (Figure 5.38), you would
use the following command:
Connect-VMNetworkAdapter VMNetworkAdapter $VMNic SwitchName
Intel(R) Gigabit CT Desktop Adapter #2 Virtual Switch
Figure 5.38
Once you have connected the virtual network adapter to the virtual switch,
itis a good idea to verify the connection (Figure 5.39). You can do by entering
thefollowing command:
Get-VMNetworkAdapter VMName <your virtual machine name> | Select-
Object VMName, Name, SwitchName
Figure 5.39
CPU cores
When you create a new virtual machine through PowerShell, Windows
automatically assigns a single virtual processor to the virtual machine. In some
cases, however, a single virtual processor might not be sufficient. Fortunately,
PowerShell makes it possible to add virtual processors to a virtual machine.
Before you attempt to modify a virtual machines virtual processor allocation,
it is a good idea to verify the number of virtual processors currently
assigned to the virtual machine (Figure 5.40). You can do this by using
thefollowingcommand:
Get-VM <virtual machine name>| Select-Object VMName, ProcessorCount
Figure 5.40
Its a good idea to verify a virtual machines current virtual CPU count.
Once you have verified the virtual machines current virtual processor
count, you can modify the number of virtual processors that are assigned
tothevirtual machine by using the following command:
Set-VMProcessor <virtual machine name> -Count <number of virtual CPUs>
166
Understanding Hyper-V in Windows Server 2012
You can use the Set-VMProcessor cmdlet to configure a virtual machines virtual CPU usage.
Of course there are also some other switches that you can use with
theSetVMProcessor cmdlet. For instance, if you want to set a reserve,
maximum and relative weight value, you can use a command like this:
Set-VMProcessor <virtual machine name> -Count 2 Reserve 10 Maximum
75 RelativeWeight 200
In case you are not familiar with these particular values, here are their
meanings:
Weight A relative weight that affects how much CPU time a virtual
machine will receive. The default weight is 100.
You can also use the Set-VMProcessor cmdlet to enable compatibility for
older operating systems by including the Compatibility For Older Operating
Systems Enabled switch in the command, as in the following example:
Set-VMProcessor <virtual machine name>
-CompatibilityForOlderOperatingSystemsEnabled $true
167
Understanding Hyper-V in Windows Server 2012
This command (Figure 5.42) works really well for creating a virtual machine
andits virtual hard disk. The problem is that the virtual machine is still abit
lacking. By default, this virtual machine is only equipped with 512 MB of
memory, a single virtual processor, and the virtual network adapter is not
connected to a virtual switch (Figure 5.43). Never mind the fact that you might
need to create some additional virtual hard disks for the virtual machine.
Figure 5.42
You can create a virtual hard disk and a virtual machine at the same time.
Figure 5.43
Unfortunately, you cant do much more with the New-VM cmdlet. You can
specify startup memory, but thats about it. That being the case, what follows
is a set of line-by-line instructions for creating and provisioning a new
virtualmachine.
168
Understanding Hyper-V in Windows Server 2012
This example illustrates how to create a new virtual machine named NewVM5.
The virtual machine will be equipped with two 50-GB virtual hard disks, two
gigabytes of virtual memory, four virtual processors, and it will be connected
to a virtual switch.
Start by creating the virtual machine and its 50-GB boot drive (Figure 5.44),
using the following command:
New-VM Name NewVM5 NewVHDPath F:\NewVM5\disk1.VHDX
NewVHDSize 50GB Path F:\NewVM5
Figure 5.44
You can create a new virtual machine from the command line.
Now that you have created the virtual machine, you need to provision it. Start
by adding the second 50-GB virtual hard disk (Figure 5.45). You can create
anew hard disk using this command:
New-VHD F:\NewVM5\Disk2.VHDX Size 50GB
Figure 5.45
The new virtual hard disk is not attached to the virtual machine.
169
Understanding Hyper-V in Windows Server 2012
This command not only displays the virtual hard disks that are in use, it also
shows which IDE ports are currently in use. When you join the newly created
virtual hard disk to the virtual machine, you will have to choose a set of
ports that are not in use. For example, to use IDE port 0.1 you would use
thiscommand:
Add-VMHardDiskDrive NewVM5 IDE 0 1 Path F:\NewVM5\Disk2.vhdx
The command does not generate any output, so to verify its success you need
to reissue the Get-VMHardDiskDrive cmdlet (Figure 5.47) as shown below:
Get-VMHardDiskDrive NewVM5
Figure 5.47
You must add the virtual hard disk to the virtual machine.
Now that the virtual hard disks are in place, you simply need to provision
memory, CPU and network connectivity. The task of provisioning memory
and CPU resources to the new virtual machine is easy (Figure 5.48) and can be
accomplished using these commands:
Set-VMMemory NewVM5 Startup 4GB
Set-VMProcessor NewVM5 Count 4
Figure 5.48
The last step in the process is to connect the virtual network adapter
tothevirtual switch. As you may recall, this isnt a single-step process. You
have to retrieve both the name of the virtual network adapter and the name
of thevirtual switch (Figure 5.49). To retrieve the name of the virtual adapter,
usethe following command:
$VMNic = Get-VMNetworkAdapter VMName <virtual machine name>
Next, you need to retrieve the name of the virtual switch. You can do this by
using the following command:
Get-VMSwitch | Select-Object Name
Now you need to connect the virtual network adapter to the virtual switch by
using this command:
Connect-VMNetworkAdapter VMNetworkAdapter $VMNic SwitchName
<virtual switch name>
You can use the following command to verify connectivity:
Get-VMNetworkAdapter VMName <your virtual machine name> | Select-
Object VMName, Name, SwitchName
170
Understanding Hyper-V in Windows Server 2012
Figure 5.49
The new virtual machine is now fully provisioned. You can verify all of
thevirtual machine settings through the Hyper-V Manager (Figure 5.50).
Figure 5.50
You can use the Hyper-V Manager to verify the virtual machine settings.
171
Understanding Hyper-V in Windows Server 2012
After you have created a snapshot, you probably want to verify that
thesnapshot exists. One way of doing this is to select the virtual machine
within the Hyper-V Manager and look at the Snapshots pane (Figure 5.53).
Of course, this chapter is all about PowerShell, so if you want to verify
thesnapshot through PowerShell, you can use the Get-VMSnapshot cmdlet
(Figure 5.54) shown below:
Get-VMSnapshot VMName <Virtual machine name>
172
Understanding Hyper-V in Windows Server 2012
Figure 5.53
Figure 5.54
Things get a bit trickier if you want to restore a snapshot in order to revert
avirtual machine to a prior state. You can roll back a virtual machine by using
the Restore-VMSnapshot command (Figure 5.55). This command requires you
to provide the name of the virtual machine and the name of the snapshot. You
can enter this information manually, but it is a lot easier to use a command like
this one:
Restore-VMSnapshot Name (Get-VMSnapshot VMName <virtual machine
name>).Name VMName <virtual machine name>
Figure 5.55
For example, if you want to roll back a virtual machine named NewVM1
tothestate in which it existed when the most recent snapshot was created,
youcan use this command:
Restore-VMSnapshot Name (Get-VMSnapshot VMName NewVM1).Name
VMName NewVM1
When you enter this command, PowerShell will prompt you to confirm that you
want to perform the rollback.
173
Understanding Hyper-V in Windows Server 2012
If you decide instead to remove the most recently created virtual machine
snapshot, the command syntax is exactly the same, except that you
would use the Remove-VMSnapshot cmdlet (Figure 5.56) instead of
theRestoreVMSnapshot cmdlet. The syntax is as follows:
Remove-VMSnapshot Name (Get-VMSnapshot VMName <virtual machine
name>).Name VMName <virtual machine name>
Figure 5.56
It is worth noting that this command does not prompt you for confirmation
before deleting the snapshot. Therefore, you should exercise extreme caution
when using the Remove-VMSnapshot cmdlet.
174
Understanding Hyper-V in Windows Server 2012
Getting help
Although you can do a lot with regard to managing Hyper-V through
PowerShell, the PowerShell cmdlets and their syntaxes are sometimes
difficult to remember. Fortunately, Microsoft provides a number of different
mechanisms to help you use PowerShell.
The question mark switch is used to retrieve the full syntax for any PowerShell cmdlet.
Any time you use the question mark switch, PowerShell asks you if you want
to run the Update-Help cmdlet. The Update-Help cmdlet causes PowerShell
to download the latest help files from the Internet. When the help file update
completes, the full command syntax will be displayed.
Get-Help
PowerShell cmdlets are a combination of nouns and verbs. Sometimes,
however, it can be difficult to remember what noun-verb combinations can be
used together, and this is where the Get-Help cmdlet comes into play. Get-Help
can show you all of the nouns that can be used with a particular verb or all of
the verbs that can be used with a specific noun. For example, in Hyper-V many
of the cmdlets are designed to be used on virtual machines and therefore use
VM as a noun (Get-VM, Set-VM, etc.). If you want to see all of the actions that
can be performed on a VM (Figure 5.59), you can use the following command:
Get-Help *-VM
175
Understanding Hyper-V in Windows Server 2012
Figure 5.59
These are all of the verbs that can be used with the VM noun.
As previously mentioned, Get-Help can be used with both nouns and verbs.
Notice in Figure 5.59 that the last cmdlet on the list is Suspend-VM. If you are
curious as to whether the Suspend verb can be used with nouns other than VM,
you can enter this command:
Get-Help Suspend-*
When you enter this command (Figure 5.60), you will see that PowerShell
uses the Suspend verb for a number of different purposes, some of which are
not even related to Hyper-V. For example, you can use the Suspend verb to
suspend a service or a print job.
Figure 8.60
The Get-Help cmdlet can help you to figure out what noun and verb combinations will
worktogether.
What-If
As you have no doubt noticed throughout this chapter, some PowerShell
commands are complicated. That being the case, it would be nice to have
a way to make sure that you are entering the correct command before you
actually press Enter. The good news is that Windows gives you a way to
find out what a specific PowerShell command would do before you actually
execute the command. The trick is to append the WhatIf switch to the end of
thecommand.
For example, suppose that you werent quite sure what would happen if you
executed the New-VM command. You could append the WhatIf switch to
thecommand (Figure 5.61) and PowerShell would tell you that the command
would create a new virtual machine named New Virtual Machine.
176
Understanding Hyper-V in Windows Server 2012
Figure 5.61
The WhatIf switch is used to find out what will happen if you perform a certain command.
It is worth noting that not every PowerShell cmdlet can be used with
WhatIf. Tosee which cmdlets support the use of WhatIf (Figure 5.62), enter
thefollowing command:
Get-Command | Where Definition Like *whatif*
Figure 5.62
IntelliSense
In addition to the PowerShell interface that is shown throughout this chapter,
Microsoft also provides a feature called the PowerShell Integrated Scripting
Environment (ISE). In the Windows Server 2012 version of PowerShell,
theIntegrated Scripting Environment contains a feature called IntelliSense,
which anticipates the command that you are about to type and offers help as
you enter the command.
To see how this feature works, go to your Hyper-V servers Metro interface,
click the Administrative Tools tile and double-click on the Windows PowerShell
ISE command (Figure 5.63), which is found on the Administrative Tools list.
177
Understanding Hyper-V in Windows Server 2012
Figure 5.63
The Windows PowerShell ISE icon is found on the Administrative Tools menu.
When the Windows PowerShell ISE window opens, start typing a PowerShell
command. As you type, the IntelliSense feature will engage and help you with
the commands syntax (Figure 5.64). For instance, if you type New-V, then
IntelliSense will show you all of the cmdlets that start with New-V. As you
progress through the list of commands, IntelliSense even offers syntax help.
Figure 5.64
178
Understanding Hyper-V in Windows Server 2012
Figure 5.65
TechNet
Finally, Microsoft TechNet is a great resource for getting help with PowerShell
commands. The page is located at: http://technet.microsoft.com/en-us/library/
hh848559.aspx (Figure 5.66) and contains a full list of every available Hyper-V-
related cmdlet. Clicking on a cmdlet takes you to a page that provides the full
syntax (Figure 5.67) and some usage examples for the cmdlet.
179
Understanding Hyper-V in Windows Server 2012
Figure 5.66
TechNet provides a reference for all of all of the Hyper-V related cmdlets.
Figure 5.67
Clicking on a link takes you to a page with the cmdlets syntax and usage examples.
180
Understanding Hyper-V in Windows Server 2012
Chapter 6
Virtual Machine
Management
Although much of this book deals with managing Hyper-V,
host-level management would be pointless without
virtual machines. This chapter explains how to create
virtual machines using the Hyper-V Manager andhow to
make configuration changes to virtual machines asyour
needsevolve.
181
Understanding Hyper-V in Windows Server 2012
Right-click on the host server and choose the New | Virtual Machine command.
2. When the New Virtual Machine Wizard begins, click Next to bypass
thewizards Welcome screen.
3. Enter a unique name for the virtual machine. Keep in mind that this name
is used to identify the virtual machine in the Hyper-V Manager (Figure 6.2).
The name is not automatically assigned as the guest operating systems
computer name, so after you install an operating system onto the virtual
machine you will have to manually rename Windows to match the virtual
machines name.
4. Select the checkbox for Store the virtual machine in a different location
and enter a path where the virtual machine should be stored. Thepath
should normally point to a high-performance, fault tolerant storage array
with plenty of free space. If the virtual machine is going to be clustered,
the virtual machine location should ideally point to aCluster Shared
Volume.
5. Click Next.
182
Understanding Hyper-V in Windows Server 2012
Figure 6.2
Provide a name for the new virtual machine and specify the virtual machines location.
183
Understanding Hyper-V in Windows Server 2012
10. Verify that the Create a Virtual Hard Disk option is selected (Figure 6.5).
11. Enter a name for the virtual hard disk that will be created.
12. Provide a location for the virtual hard disk if necessary. In general,
thelocation should match the virtual machine location you
specifiedearlier.
13. Provide a size for the virtual hard disk.
14. Click Next.
184
Understanding Hyper-V in Windows Server 2012
Figure 6.5
Specify the name, location, and size of the virtual hard disk.
15. Choose the option to install an operating system from a boot CD or DVD
(Figure 6.6).
16. Click Next.
Figure 6.6
Choose how you want to install an operating system onto the new virtual machine.
185
Understanding Hyper-V in Windows Server 2012
The new virtual machine should be listed within the Hyper-V Manager.
186
Understanding Hyper-V in Windows Server 2012
3. Choose the Start option from the virtual machines Action menu to start
the virtual machine.
4. When prompted, press any key to boot from the installation DVD.
One common problem with the technique described above is that the DVD
drive can only be used by one virtual machine at a time. If the DVD drive is
already in use, you will receive an error message indicating that thevirtual
machine failed to start (Figure 6.9).
Figure 6.9
You will receive this error message if the DVD drive is being used by another virtual machine.
When this happens you can fix the problem by releasing the DVD drive from
the server that is currently using it. To do so, follow these steps:
1. I n the Hyper-V Manager, double click on the virtual machine that is
currently using the DVD drive. This will open the virtual machine.
2. Choose the Release command from the virtual machines Media menu
(Figure6.10).
Figure 6.10
You must release the DVD drive from the virtual machine that is currently using it.
187
Understanding Hyper-V in Windows Server 2012
The exact method used to change a virtual machines computer name varies
considerably depending on the operating system that is running on the virtual
machine. To change the computer name for a virtual machine that is running
Windows 8, follow these steps:
1. Open the Hyper-V Manager.
2. Double-click on the virtual machine whose name you want to change.
Thiswill display the virtual machines console.
3. Log in to the virtual machine.
4. Click the Desktop tile.
5. Right-click on the Start tile and choose the System command from
theright-click menu (Figure 6.12).
188
Understanding Hyper-V in Windows Server 2012
Figure 6.12
6. When the System dialog box appears, click Change Settings (Figure 6.13).
Figure 6.13
7. When the System Properties sheet appears, make sure that the Computer
Name tab is selected and click the Change button.
8. Enter the new computer name and click OK (Figure 6.14). A reboot will be
required for the new name to take effect.
189
Understanding Hyper-V in Windows Server 2012
Figure 6.14
190
Understanding Hyper-V in Windows Server 2012
Figure 6.15
Choose the Insert Integration Services Setup Disk option from the Action menu.
4. When the AutoPlay screen appears, click the Install Hyper-V Integration
Services option.
191
Understanding Hyper-V in Windows Server 2012
6. When the upgrade process completes you must reboot the virtual
machine. When prompted, click Yes to restart the virtual machine
(Figure6.17).
Figure 6.17
192
Understanding Hyper-V in Windows Server 2012
The Settings page allows you to modify the virtual machines settings.
Theindividual settings are discussed in the sections below.
Adding hardware
The first option listed on the virtual machines Settings screen is the Add
Hardware option (Figure 6.19). You can use this option to add four different
types of hardware to the virtual machine. This includes:
SCSI Controllers
Network Adapters
Legacy Network Adapters
Fibre Channel Adapters
Network-related hardware is discussed in Chapter 10.
193
Understanding Hyper-V in Windows Server 2012
Figure 6.19
194
Understanding Hyper-V in Windows Server 2012
Figure 6.20
Click Add Hardware and then click on the SCSI Controller option and click Add.
195
Understanding Hyper-V in Windows Server 2012
Figure 6.21
Make sure that the Hard Drive option is selected and click Add.
6. On the following screen, make sure that your new SCSI controller is
selected on the Controller drop-down list (Figure 6.22).
7. Use the Location drop-down list to select a location that is not currently
inuse.
8. Choose either the Virtual Hard Disk option (to connect a virtual hard
disk to the SCSI controller) or the Physical Hard Disk option (to connect
theSCSI controller to a physical SCSI disk as a pass-through disk).
9. Specify the physical or virtual hard disk that you want to use (you can
create a new virtual hard disk by clicking the New button if necessary).
10. Click OK.
196
Understanding Hyper-V in Windows Server 2012
Figure 6.22
BIOS
The Settings screens BIOS section allows you to configure thestartup
behavior for the selected virtual machine (Figure 6.23). The BIOS page contains
acheckbox you can select to turn the Num Lock on or off at boot time. You
can also control the boot device order by selecting a boot device and using
theMove Up and Move Down buttons to change the devices priority.
197
Understanding Hyper-V in Windows Server 2012
Figure 6.23
The BIOS screen lets you control the boot order and the startup state of the Num Lock key.
Memory
The Memory page allows you to control the amount of memory that is
assigned to the virtual machine (Figure 6.24). The Startup RAM field controls
theamount of memory that will initially be assigned to the virtual machine.
Ifdynamic memory is not being used, the amount of memory specified in
theStartup Memory field will be available to the virtual machine the entire time
that the virtual machine is powered on.
198
Understanding Hyper-V in Windows Server 2012
Figure 6.24
199
Understanding Hyper-V in Windows Server 2012
Processors
The Processors setting allows you to control the number of virtual processors
that are assigned to a virtual machine. By default each virtual machine is
assigned one virtual processor, but you can change this value if necessary
andprovision a virtual machine with additional virtual processors (Figure 6.25).
Figure 6.25
200
Understanding Hyper-V in Windows Server 2012
In addition, Hyper-V lets you configure various limits on virtual processor usage
as a way of preventing a virtual machine from using too many physical CPU
resources. The Settings that are available to you include:
Virtual Machine Reserve (percentage) This setting allows you to reserve
a percentage of a single physical CPU core for the virtual machine.
Percent Total System Resources The Percent Total System Resources
setting allows you to control the percentage of the servers total
processing power that the virtual machine is allowed to use.
Virtual Machine Limit (percentage) This value reflects the maximum
percentage of allocated processors that the virtual machine is allowed
touse.
Relative Weight Virtual machines that have been assigned higher
relative weights receive more CPU time than virtual machines with lower
relative weights.
Disks
When you created a virtual machine you got a taste of the process involved
in setting up a virtual hard disk, but a single virtual machine often requires
multiple virtual hard disks. There are several concepts that you need to
understand when creating virtual hard disks in Hyper-V.
One of the first decisions you need to make is the virtual hard disk format.
Hyper-V lets you choose between creating a VHD- and a VHDX-based virtual
hard disk. VHD is the legacy virtual hard disk format that was introduced in
Windows Server 2008 and continued to be used in Windows Server 2008R2.
VHD-based virtual hard disks have a maximum capacity of just under 2 TB
(2,040 GB).
In contrast, VHDX is the next-generation virtual hard disk format, which was
introduced in Windows Server 2012. VHDX-based virtual hard disks have
amaximum capacity of 64 TB. In addition, the VHDX format is designed to be
more resilient than the VHD format, thus providing better protection against
disk errors that might result from power failures.
Another important consideration is the type of virtual hard disk that you are
creating. Hyper-V gives you three choices including:
Fixed Size
Dynamically Expanding
Differencing
When you create a fixed size virtual hard disk, the virtual machine will claim
the physical disk space required by the virtual hard disk as soon as the virtual
hard disk is created. For example, if you create a 1-TB fixed size drive, then
a1-TB virtual hard disk file will be immediately created. The advantage tothis
approach is that fixed size virtual hard disks offer superior performance
compared todynamically expanding virtual hard disks.
201
Understanding Hyper-V in Windows Server 2012
202
Understanding Hyper-V in Windows Server 2012
Figure 6.26
Choose the controller to which you want to bind the new virtual hard disk, choose the Hard
Disk option and click Add.
203
Understanding Hyper-V in Windows Server 2012
Figure 6.27
7. When the New Virtual Hard Disk Wizard opens, click Next to bypass
theWelcome screen.
8. Choose the desired virtual disk format (Figure 6.28). As a general rule you
should use VHDX unless there is a chance that you may eventually need
to move the virtual disk or the corresponding virtual machine to a legacy
Hyper-V server.
204
Understanding Hyper-V in Windows Server 2012
Figure 6.28
9. Click Next.
10. Choose the virtual hard disk type (Figure 6.29).
11. Click Next.
Figure 6.29
Choose the type of virtual hard disk that you want to create.
205
Understanding Hyper-V in Windows Server 2012
12. Enter a name for the virtual hard disk that you are creating and specify
thelocation where you would like to store the new virtual hard disk
(Figure6.30).
13. Click Next.
Figure 6.30
14. Specify the size of the virtual hard disk that you are creating or use
theoption to copy the contents of a physical hard disk.
15. Click Next.
16. Take a moment to review the summary screen to make sure that all of
theinformation that has been presented is correct. Assuming that all is
well, click Finish to create the new virtual hard disk.
COM ports
Virtual COM ports are a feature that you will probably never have to use.
Theyare provided solely for backward compatibility with legacy physical
servers. You can map Virtual COM ports to a named pipe by completing
thesesteps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine for which you want to configure a COM
port, and select the Settings command from the right-click menu.
3. When the Settings page opens, select the COM port that you want to
configure (Figure 6.31).
4. Select the Named Pipe option.
206
Understanding Hyper-V in Windows Server 2012
Diskette drives
Another feature that is provided solely for the purpose of providing backward
compatibility with aging physical hardware is the virtual diskette drive feature.
This feature allows Hyper-V to emulate a floppy disk drive. It is worth noting
however, that a virtual machine cannot be configured to use a physical
floppydrive.
Unlike virtual hard disks, virtual diskette drives must be created outside
of avirtual machine. You can create a virtual diskette drive by completing
thesesteps:
1. Open the Hyper-V Manager.
2. Right-click on the name of the host server and select the New | Floppy
Disk commands from the right-click menu (Figure 6.32).
3. Navigate to the location where you want to store the virtual floppy disk.
4. Enter a name for the virtual floppy disk and click Create.
207
Understanding Hyper-V in Windows Server 2012
Figure 6.32
Right-click on the host server and choose the New | Floppy Disk commands from
therightclick menu.
Once the virtual floppy disk has been created, you can configure a virtual
machine to use it by completing these steps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine to which you want to attach the virtual
floppy disk and select the Settings command from the right-click menu.
3. Click on Diskette Drive (Figure 6.33).
4. Click on the Virtual Floppy Disk (.VFD) File option.
5. Click the Browse button and then navigate to and select the virtual floppy
disk file that you created earlier.
6. Click Open.
7. Click OK.
208
Understanding Hyper-V in Windows Server 2012
Figure 6.33
Click on Diskette Drive and specify the virtual floppy disk you created earlier.
209
Understanding Hyper-V in Windows Server 2012
Figure 6.34
You can rename a virtual machine and enter notes about the virtual machines purpose.
210
Understanding Hyper-V in Windows Server 2012
Figure 6.35
211
Understanding Hyper-V in Windows Server 2012
Figure 6.36
You can specify the location for a virtual machines smart paging file.
212
Understanding Hyper-V in Windows Server 2012
213
Understanding Hyper-V in Windows Server 2012
The next best option is shutting down the guest operating system. This
option ensures that the virtual machine is brought down in a clean state.
However, this option is valid only if the Integration Services are installed on
thevirtualmachine.
You can control a virtual machines automatic stop action by following
thesesteps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine and choose the Settings command from
the right-click menu.
3. Locate the Management section and click on Automatic Stop Action
(Figure 6.38)
4. Choose the desired automatic stop action.
5. Click OK.
Figure 6.38
214
Understanding Hyper-V in Windows Server 2012
215
Understanding Hyper-V in Windows Server 2012
Figure 6.39
216
Understanding Hyper-V in Windows Server 2012
Figure 6.41
Right-click on the virtual machine and select the Snapshot command from
therightclickmenu.
The Snapshots pane lists a date and a time stamp for each snapshot.
Deleting snapshots
Snapshots diminish a virtual machines read performance. That being the case,
it is usually best to keep only the snapshots that you need. When a snapshot is
no longer needed, you can remove it by completing these steps:
1. Open the Hyper-V Manager.
2. Select the virtual machine whose snapshots you want to delete.
217
Understanding Hyper-V in Windows Server 2012
3. Right-click on the snapshot that you want to delete and select the Delete
Snapshot command from the right-click menu (Figure 6.43).
4. When you are prompted for confirmation, click the Delete button.
Figure 6.43
Right-click on the unwanted snapshot and choose the Delete Snapshot command.
218
Understanding Hyper-V in Windows Server 2012
Figure 6.44
Right-click on the oldest snapshot that you want to delete and select the Delete Snapshot
Subtree command from the right-click menu.
Renaming snapshots
When you create a new snapshot, Hyper-V labels the snapshot with the name
of the virtual machine and the date and time when the snapshot was created.
However, it can be more helpful to assign the snapshot a meaningful name that
indicates why you created the snapshot. You can accomplish this by performing
these steps:
1. Open the Hyper-V Manager.
2. Select the virtual machine on which you want to rename a snapshot.
3. Right-click on the snapshot that you want to rename and choose
therename option from the right-click menu (Figure 6.45).
4. Rename the snapshot.
219
Understanding Hyper-V in Windows Server 2012
Figure 6.45
Applying snapshots
Its best to avoid applying snapshots if you can, because there can be
consequences to rolling a virtual machine back to an earlier point in time
(particularly with application servers that are not intended to be used with
snapshotting). However, the need to revert a virtual machine to a previous state
is sometimes unavoidable. To apply a snapshot, follow these steps:
1. Open the Hyper-V Manager.
2. Select the virtual machine that you need to roll back.
3. Select the snapshot that you want to apply.
4. Right-click on the snapshot and select the Apply command from
therightclick menu (Figure 6.46).
220
Understanding Hyper-V in Windows Server 2012
Figure 6.46
Right-click on the snapshot and choose the Apply command from the right-click menu.
5. Choose whether you simply want to apply the snapshot or if you want to
take another snapshot before you apply the snapshot (Figure 6.47). Using
the Take Snapshot and Apply option gives you the ability to roll back
thevirtual machine to its current state in the event that you accidentally
apply the wrong snapshot.
Figure 6.47
You can optionally take another snapshot prior to applying the snapshot.
6. When the snapshot has been applied, the Now indicator will be moved to
just beneath the snapshot that you have applied (Figure 6.48). The other
snapshots still exist and can be applied or deleted.
Figure 6.48
221
Understanding Hyper-V in Windows Server 2012
Chapter 7
P2V Conversions
After setting up a new Hyper-V deployment, one of
thefirst things that you will probably want to do is to
begin virtualizing your physical servers. This is what is
known as physical-to-virtual or P2V conversion. Hyper-V
does not contain any built-in tools for performing
P2Vconversions, but you can use Microsofts System
Center Virtual Machine Manager or any number of third-
party tools to perform the conversion.
222
Understanding Hyper-V in Windows Server 2012
Conversion planning
Microsofts primary tool for performing P2V conversions is System Center
Virtual Machine Manager (SC VMM). SC VMM provides two different methods
for performing P2V conversions. You can perform an online conversion or
you can perform an offline conversion. An online P2V conversion is run
against aphysical server that is actively running. An offline conversion takes
thephysical server offline prior to performing the conversion.
Regardless of whether you are performing an online or offline conversion,
it is extremely important that you do not use this method to perform a P2V
conversion of virtual machines that have encrypted volumes. Doing so will
likely render the volumes unreadable.
Click on the Create Virtual Machine button and choose the Convert Physical Machine option.
223
Understanding Hyper-V in Windows Server 2012
4. When the Convert Physical Server (P2V) Wizard opens, enter the name
orIP address of the computer that you want to convert (Figure 7.2).
Figure 7.2
Enter the name or IP address of the physical computer that you want to convert.
224
Understanding Hyper-V in Windows Server 2012
Figure 7.3
Click the Scan System button to perform a hardware inventory on the computer that is
being converted.
225
Understanding Hyper-V in Windows Server 2012
Figure 7.4
12. Make any necessary adjustments to the virtual hard disks sizes, types
orchannels.
13. Click Next.
14. Specify the number of virtual processors and the amount of memory that
you want to assign to the virtual machine (Figure 7.5). By default, System
Center Virtual Machine Manager will use the same amount of memory
andthe same number of processor cores as in the physical machine that
you are converting.
15. Click Next.
226
Understanding Hyper-V in Windows Server 2012
Figure 7.5
Specify the hardware you want to allocate to the new virtual machine.
16. Select the Hyper-V host that will host the newly created virtual machines
(Figure 7.6). Hyper-V hosts are assigned a star rating to reflect their
suitability for hosting the newly created VM.
17. Click Next.
227
Understanding Hyper-V in Windows Server 2012
Figure 7.6
Select the Hyper-V host that will host the newly created virtual machine.
18. Specify a location on the target server where the virtual machine files
should be stored.
19. Click Next.
20. Specify the network adapter configuration for the new virtual machine
(Figure 7.7).
21. Click Next.
228
Understanding Hyper-V in Windows Server 2012
Figure 7.7
22. Specify your preferred startup action for the virtual machine (Figure 7.8).
23. Specify your preferred stop action for the virtual machine.
24. Click Next.
229
Understanding Hyper-V in Windows Server 2012
Figure 7.8
Specify a startup action and a stop action for the new virtual machine.
25. Take a moment to review the Conversion Information screen to make sure
that no issues are detected (Figure 7.9). If any issues are reported, resolve
them and click the Check Again button.
26. Click Next.
230
Understanding Hyper-V in Windows Server 2012
Figure 7.9
Make sure there are no issues standing in the way of the virtual machine
conversionprocess.
27. Review the information presented on the summary screen to make sure it
is correct.
28. Click the Create button to begin the conversion process.
29. Go to the Jobs tab to confirm that the conversion is being performed
(Figure 7.10).
231
Understanding Hyper-V in Windows Server 2012
Figure 7.10
You can use the Jobs tab to monitor the conversion process.
232
Understanding Hyper-V in Windows Server 2012
Figure 7.11
Click on the Create Virtual Machine button and choose the Convert Physical
Machineoption.
4. When the Convert Physical Server (P2V) Wizard opens, enter the name
orIP address of the computer that you want to convert (Figure 7.12).
233
Understanding Hyper-V in Windows Server 2012
Figure 7.12
Enter the name or IP address of the physical computer that you want to convert.
234
Understanding Hyper-V in Windows Server 2012
Figure 7.13
Click the Scan System button to perform a hardware inventory on the computer that is
being converted.
235
Understanding Hyper-V in Windows Server 2012
Figure 7.14
12. Make any necessary adjustments to the virtual hard disks sizes, types
orchannels.
13. Click the Conversion Options link, located in the lower left portion of
thewizard.
14. Select the Offline Conversion option (Figure 7.15). It is also generally
recommended that you use the option to turn off the source computer
after the conversion completes.
236
Understanding Hyper-V in Windows Server 2012
Figure 7.15
237
Understanding Hyper-V in Windows Server 2012
Figure 7.16
238
Understanding Hyper-V in Windows Server 2012
Figure 7.17
Specify the hardware that you want to allocate to the new virtual machine.
20. Select the Hyper-V host for the newly created virtual machines (Figure
7.18). Hyper-V hosts have a star rating that reflects their suitability for
hosting the newly created VM.
21. Click Next.
239
Understanding Hyper-V in Windows Server 2012
Figure 7.18
Select the Hyper-V host for the newly created virtual machine.
22. Specify a location on the target server where the virtual machine files
should be stored.
23. Click Next.
24. Specify the network adapter configuration for the new virtual machine
(Figure 7.19).
25. Click Next.
240
Understanding Hyper-V in Windows Server 2012
Figure 7.19
26. Specify the preferred startup action for the virtual machine (Figure 7.20).
27. Specify the preferred stop action for the virtual machine.
28. Click Next.
241
Understanding Hyper-V in Windows Server 2012
Figure 7.20
Specify a startup action and a stop action for the new virtual machine.
29. Take a moment to review the Conversion Information screen to make sure
that no issues are detected (Figure 7.21). If any issues are reported, resolve
them and click the Check Again button.
30. Click Next.
242
Understanding Hyper-V in Windows Server 2012
Figure 7.21
Make sure that there are no issues standing in the way of the virtual machine
conversionprocess.
31. Review the information presented on the summary screen to make sure
itis correct.
32. Click the Create button to begin the conversion process.
33. Go to the Jobs tab to confirm that the conversion is being performed
(Figure 7.22).
243
Understanding Hyper-V in Windows Server 2012
Figure 7.22
You can use the Jobs tab to monitor the conversion process.
244
Understanding Hyper-V in Windows Server 2012
245
Understanding Hyper-V in Windows Server 2012
Chapter 8
Replication
Of all the new features in Hyper-V 3.0, replication is
ahands-down favorite. Replication makes it possible
tocreate replica virtual machines on a secondary Hyper-V
server. You can use the replica as a relatively up-todate
backup in the event that something happens toyour
primary Hyper-V server.
246
Understanding Hyper-V in Windows Server 2012
System requirements
There arent any special system requirements for using replication beyond
thesystem requirements for running Hyper-V. Each edition of Windows Server
2012 supports Hyper-V replication. However, there is a big difference in
theway the two editions of Windows Server 2012 are licensed.
When planning your licensing, consider the number of virtual machines that
you plan to replicate and whether or not those virtual machines are running
Windows Server 2012. Windows Server 2012 Standard Edition andDatacenter
Edition have exactly the same capabilities. The difference between the two
editions lies in the number of virtual servers for which they are licensed.
Windows Server 2012 Standard Edition is licensed for up to two virtual
instances of Windows Server 2012. Windows Server 2012 Datacenter Edition,
on the other hand, is licensed for an unlimited number of virtual instances of
the Windows Server 2012 operating system. Thus, you should consider the
most appropriate licenses for both the source server and destination server
(the replica host) before you start configuring replication.
247
Understanding Hyper-V in Windows Server 2012
Configuration planning
Although Hyper-Vs replication feature is designed to be easy to set up,
there are a number of aspects to the configuration process that you must
consider before you actually set up replication. Some of the more important
aspectsinclude:
Clustering
Destination Server (hardware (NIC, storage, etc.))
Authentication Type
Compression
Virtual Machine and Virtual Hard Disk Selection
Initial Synchronization
248
Understanding Hyper-V in Windows Server 2012
Figure 8.1
249
Understanding Hyper-V in Windows Server 2012
Figure 8.2
Figure 8.3
250
Understanding Hyper-V in Windows Server 2012
6. Enable either the Hyper-V Replica HTTP or the Hyper-V Replica HTTPS
feature (Figure 8.4).
7. Click OK.
Figure 8.4
Hyper-V Replica traffic must be able to pass through the Windows firewall.
251
Understanding Hyper-V in Windows Server 2012
Figure 8.5
252
Understanding Hyper-V in Windows Server 2012
Figure 8.6
8. Click Next.
9. Select the virtual hard disks that you want to replicate (Figure 8.7).
Figure 8.7
253
Understanding Hyper-V in Windows Server 2012
14. Specify when you would like the replication process to begin.
15. Click Next.
16. Verify the summary information.
17. Click Finish.
18. Verify that the Hyper-V Manager shows the virtual machines status as
Initial Replication (Figure 8.9).
254
Understanding Hyper-V in Windows Server 2012
Figure 8.9
Figure 8.10
The replica server should be receiving the replicated data from the source server.
The instructions below guide you through the process of replicating aclustered
virtual machine to a standalone host (this is the most common form of
clusterbased replication). As with standalone replication, you must perform
some steps on the source server (in this example, a cluster node where theVM
resides) and other steps on the destination server (a standalone VM in this
case). To configure the Hyper-V replica, complete these steps:
255
Understanding Hyper-V in Windows Server 2012
Figure 8.11
256
Understanding Hyper-V in Windows Server 2012
Figure 8.12
Hyper-V Replica traffic must be able to pass through the Windows firewall.
257
Understanding Hyper-V in Windows Server 2012
First you need to install the Hyper-V Replica Broker on the Hyper-V cluster. To
do this, complete the following steps:
1. Open the Server Manager.
2. Choose the Failover Cluster Manager command from the Manage menu.
3. Navigate through the console tree to Failover Cluster Manager | <your
cluster> | Roles.
4. Right-click on the Roles container and choose the Configure Role
command from the right-click menu (Figure 8.13).
Figure 8.13
Right-click on the Roles container and select the Configure Role command from
therightclick menu.
258
Understanding Hyper-V in Windows Server 2012
Figure 8.14
Choose the Hyper-V Replica Broker from the list of roles and click Next.
7. Enter a name that clients can use when connecting to the Hyper-V
ReplicaBroker.
8. Enter an IP address that the Hyper-V Replica Broker can use andclickNext.
9. Take a moment to verify the information presented on the summary
screen and click Next.
10. When the installation process completes, click Finish.
Now that you have installed the Hyper-V Replica Broker, the next step is to
designate a virtual machine for replication. You can accomplish this task by
following these steps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine that you want to replicate.
3. Choose the Replication | Enable Replication commands from
therightclickmenu.
4. When the Enable Replication wizard begins, click Next to bypass
thewizards Welcome screen.
5. When prompted, enter the name of the replica server and click Next
(Figure 8.15).
259
Understanding Hyper-V in Windows Server 2012
Figure 8.15
260
Understanding Hyper-V in Windows Server 2012
Figure 8.16
8. Click Next.
9. Select the virtual hard disks that you want to replicate (Figure 8.17).
Figure 8.17
261
Understanding Hyper-V in Windows Server 2012
14. Specify when you would like the replication process to begin.
15. Click Next.
16. Verify the summary information.
17. Click Finish.
18. Click Close when you see the Replication enabled successfully dialog box
(Figure 8.19).
19. Verify that the Hyper-V Manager shows the virtual machines status
asInitial Replication.
262
Understanding Hyper-V in Windows Server 2012
Figure 8.19
The replica server should be receiving the replicated data from the source server.
3. Select the Replication tab at the bottom of the window (Figure 8.21).
263
Understanding Hyper-V in Windows Server 2012
Figure 8.21
Right-click on the virtual machine and select the Replication | View Replication
Healthcommands.
264
Understanding Hyper-V in Windows Server 2012
As you can see in the figure below, the Replication Health dialog box provides
detailed information about the health of thereplicationprocess (Figure 8.23).
Figure 8.23
The Replica Health dialog box provides detailed information about the health
ofthereplication process.
It's important to know that the information provided about replication health
is often inconsistent, depending on which Hyper-V server you are viewing
the health information. To illustrate the accuracy problem, check out the two
screen captures below:
Figure 8.24
The primary replica shows Replication Error and Replication Health of Critical.
265
Understanding Hyper-V in Windows Server 2012
Figure 8.25
The secondary replica shows Replication Paused and Replication Health Warning.
As you can see in the figures above, the primary Hyper-V server shows a critical
error, while the replica server shows only a warning condition. As such, the only
way to reliably assess the replicas health is to look at the health information on
both the primary and the replica server.
266
Understanding Hyper-V in Windows Server 2012
Figure 8.26
Resetting the replication statistics allows you to view the most current health information.
If after checking the most recent health information, you determine that
replication has stopped, try right-clicking on the virtual machine andchoosing
the Replication | Resume Replication commands from theright-click menus
(Figure 8.27). This restarts the replication process andwill usually fix the
replication problem.
Figure 8.27
267
Understanding Hyper-V in Windows Server 2012
If using the Resume Replication command does not fix the problem, check to
make sure that your servers have plenty of free disk space and thatthere is
still network connectivity between the servers. Its also a good idea to check
theservers event logs for any errors.
Pausing replication
If you need to take a server containing replicas offline for maintenance, it is
agood idea to pause the replication process first by following these steps:
1. Open the Hyper-V Manager on the server that needs to be taken offline.
2. Right-click on the replica virtual machine.
3. Choose the Replication | Pause Replication command from the right-click
menus (Figure 8.28).
Figure 8.28
Right-click on a replica virtual machine and choose the Replication | Pause Replication
commands from the right-click menus.
Disabling replication
If you no longer wish to replicate a virtual machine, you can permanently
disable replication by using Hyper-Vs Remove Replication function. To do so,
follow these steps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine for which you want to stop replication.
3. Select the Replication | Remove Replication commands from
therightclick menus (Figure 8.29).
268
Understanding Hyper-V in Windows Server 2012
Select the Replication | Remove Replication options from the right-click menus.
Figure 8.30
269
Understanding Hyper-V in Windows Server 2012
Figure 8.31
4. You will now see a message stating that you can create a separate virtual
machine to verify that a recovery point is able to start successfully and that
the virtual machine is running correctly (Figure 8.32).
5. Choose the recovery point from which you want to create the new
virtualmachine.
Figure 8.32
Choose the recovery point from which you want to create the new virtual machine.
270
Understanding Hyper-V in Windows Server 2012
Figure 8.33
8. Start the test virtual machine and verify that it functions properly.
In case you are wondering, when Hyper-V creates the test virtual machine, what
it is really doing is snapshotting the replica and then using a differencing disk
for the test virtual machine. This allows you to boot the test virtual machine
and interact with it, without having to worry about damaging your replica
in the process. The replication process can continue normally throughout
thetesting process.
When you have finished testing virtual machine failover, you must shut down
and delete the test virtual machine. Keep in mind that the test virtual machine
is using the same virtual hard disks as the primary replica virtual machine. This
means that it is safe to delete the test virtual machine through the Hyper-V
Manager, but you should not attempt to manually remove individual virtual
machine components through the file system.
Choose the Replication | Planned Failover commands from the right-click menu.
4. The Planned Failover dialog box lists the prerequisites you must meet
as well as the actions you must perform as a part of the planned failover.
After verifying that you have met the prerequisites, click the Failover
button.
271
Understanding Hyper-V in Windows Server 2012
Unplanned failover
An unplanned failover is a disaster recovery technique that you should use only
as a last resort. You would use unplanned failovers in situations in which your
primary Hyper-V host server has failed catastrophically and you want to switch
over to your replica. The reason why this is a last resort operation is because
unplanned failovers almost always result in data loss. Any data that has not
been replicated from the primary server to the replica is lost. You can perform
an unplanned failover by completing these steps:
1. Open the Hyper-V Manager on the host server that contains your replicas.
2. Right-click on the virtual machine that you want to fail over.
3. Choose the Failover command from the right-click menu (Figure 8.35)
Figure 8.35
You can perform an unplanned failover by right-clicking on a virtual machine and choosing
the Failover option from the right-click menu.
272
Understanding Hyper-V in Windows Server 2012
Chapter 9
Hyper-V
Management
So far this book has covered topics such as Hyper-V
deployment, virtual machine migrations and even virtual
machine creation through PowerShell. However, in any
virtual datacenter there is ongoing maintenance that
you must perform in order to keep your host servers
and virtual machines healthy. In this chapter, you will
learn about two important maintenance tasksresource
metering and patching host serverclusters.
273
Understanding Hyper-V in Windows Server 2012
Resource metering
In any virtual server environment, it is important to keep track of the resources
that virtual machines are using. Virtual servers share a finite pool of hardware
resources on the host server. If any individual virtual machine were to consume
excessive resources, it could potentially rob the other virtual machines of
thehardware they need. Resource metering allows you to keep track of
hardware usage on a per virtual machine basis.
Although it makes sense to use resource metering as a tool for measuring
performance and allocating virtual machine resources, some people use
resource metering as a way of facilitating chargebacks. In previous versions
of Hyper-V to implement chargebacks you had to either develop a custom
solution or use the Self Service Portal for System Center Virtual Machine
Manager. The Self Service Portal provided a very nice interface for tracking
chargebacks, but setup was tedious.
Hyper-V 3.0s resource metering capabilities do not include built-in chargeback
management capabilities, but they do lay the ground work for building your
own chargeback management system. Furthermore, the fact that the resource
metering capabilities are PowerShell based means that developing such
asolution is much easier than it would have been in the past.
The nice thing about Hyper-Vs resource metering capabilities is that they
are completely open ended, which means that you can easily adapt them to
your own needs. Resource metering allows you to track several different vital
statistics on a per virtual machine basis. These statistics include:
274
Understanding Hyper-V in Windows Server 2012
Figure 9.1
This command enables resource metering for all of the virtual machines that are running
on the designated host server.
Of course, you can easily enable resource metering for a single virtual machine
by altering the command slightly. For example, if you want to enable resource
metering for a virtual machine named VM2, you would use the following
command (Figure 9.2):
Get-VM VM2 | Enable-VMResourceMetering
Figure 9.2
This command changes the resource metering collection interval to one minute.
In the figure above, notice that you are adjusting thecollection period at the
host server level. You cannot change the collection period on a per virtual
machine basis.
Keep in mind that it's not a good idea to collect resource metering data once
aminute in production environments. There is a reason why Microsoft chose to
use hourly collection of metering data as the default.
275
Understanding Hyper-V in Windows Server 2012
This is the easiest way to view all of the resource metering data for a specific
virtualmachine.
276
Understanding Hyper-V in Windows Server 2012
Figure 9.5
It is possible to view the resource metering data for all of the virtual machines on the server.
277
Understanding Hyper-V in Windows Server 2012
Figure 9.6
You can use this command to determine all of the property names that are supported by
the Measure-VM cmdlet.
With that in mind, use the Select-Object cmdlet to build a report that shows
memory usage data for the virtual machines. Note that when you use the
Select-Object cmdlet, PowerShell shows you EXACTLY what you have requested
and nothing more. That being the case, you should include the VMName
property, otherwise there's no way to tell which virtual machines the metering
data belongs to. Use the following command (Figure 9.7):
Get-VM | Measure-VM | Select-Object VMName, AvgRAM, MaxRAM,
MinRAM
Figure 9.7
You can filter the Measure-VM cmdlets output to show only specific properties.
278
Understanding Hyper-V in Windows Server 2012
You can easily sort the resource metering data by using the Sort-Object cmdlet.
The lab server used in the examples in this chapter contains a reasonable
number of virtual machines, but in the real world, a Hyper-V host might have
too many virtual machines to view all of the resource metering data at once on
screen. In situations like that it is useful to narrow down the list. Fortunately,
PowerShell makes it possible to list only your top results. For example,
iftheoutput is too long andyou only want to see the three virtual machines
with the highest memory usage, you can use the First switch and the number
of virtual machines you wantto display (three in this case). The command for
thisis:
Get-VM | Measure-VM | Sort-Object Property AvgRAM Descending |
Select-Object First 3 VMName, AvgRAM, MaxRAM, MinRAM
As you can see, Figure 9.9 displays, the three virtual machines with the highest
memory use.
Figure 9.9
279
Understanding Hyper-V in Windows Server 2012
Although the example above lists only virtual machines that are powered on,
there are other ways to use this technique. You can also use this method to
locate any resource metering data. For example, you can use thetechnique to
locate virtual machines that are consuming over 4 GB of RAM on average or
virtual machines with a very high average CPU usage.
Reporting
In this chapter, you have learned how to view a variety of resource metering
data. Sometimes, however, it is more beneficial to build a report. This allows
you to track resource usage over time and makes it easier to view themetering
data when there is too much data to view on the screen. Thechapter on
PowerShell contains an entire section on reporting. It shows how to build
HTML-based reports and how to export data to a CSV file, which is viewable in
Microsoft Excel. The use of CSV files is especially handy for tracking metering
data over time.
Cluster-aware updating
One of the big problems previously with managing Hyper-V clusters in
Windows Server 2008 or 2008 R2 was that patching a Hyper-V cluster was
atedious and time-consuming process. If you wanted to patch the servers
within the cluster using only native tools, you had to manually live migrate
thevirtual machines off a cluster node, patch and reboot the node, and repeat
the process for each remaining cluster node.
280
Understanding Hyper-V in Windows Server 2012
There are some options for automating the process: you can automate cluster-
level patch management using System Center Orchestrator or System Center
2012 Virtual Machine Manager. The problem is that there are licensing costs
associated with these tools and setting up automated patch management can
be complicated.
Windows Server 2012 offers a new feature called Cluster-Aware Updating. This
feature allows you to patch the nodes in a Hyper-V cluster without having to
manually patch each node or resort to using external tools.
Cluster-Aware Updating takes a round-robin approach to patch management.
Itstarts by placing a cluster node into maintenance mode. This causes
thevirtual machines that are running on the host to be automatically live
migrated to the best possible node (as determined by the cluster).
It is worth noting that choosing the best possible node is based solely on
theamount of free memory on each cluster node. This is different from
theprocess used by System Center 2012 Virtual Machine Manager, which uses
a number of different criteria to determine the best possible cluster node.
Once the virtual machines have been live migrated off the host, the server
is patched and rebooted. The update process then takes the node out of
maintenance mode, which in turn allows it to host virtual machines once again.
Theprocess is repeated for every node in the cluster.
There are two ways to use Cluster-Aware Updating Self Updating or Remote
Updating. Self Updating is the more common of the two methods and involves
running the Cluster-Aware Update tool directly on a cluster node according to
a schedule that you set. Remote updating involves installing the Cluster-Aware
Update tool on a computer that is not a cluster node. The computer must be
running Windows Server 2012 or Windows 8.
281
Understanding Hyper-V in Windows Server 2012
Figure 9.11
9. Click Next.
10. Take a moment to verify that the Failover Cluster Management Tools will
be installed (Figure 9.13).
11. Click Install.
282
Understanding Hyper-V in Windows Server 2012
Figure 9.13
Make sure that the Failover Cluster Management Tools will be installed.
283
Understanding Hyper-V in Windows Server 2012
Figure 9.15
5. Assuming that this is the first time you have performed a Cluster-Aware
update, click on Configure Cluster Self-Updating Options.
6. When the Configure Self-Updating Options Wizard launches, click Next to
bypass the Welcome screen.
7. You should see warning that the cluster is not configured with
theClusterAware Updating clustered role (Figure 9.16). Select
thecheckbox for Add the CAU clustered role with self-updating mode
enabled to this cluster.
Figure 9.16
You must add the CAU clustered role with self-updating mode enabled to the cluster.
284
Understanding Hyper-V in Windows Server 2012
8. Click Next.
9. Set a self-updating schedule (Figure 9.17). It is best to choose an off-peak
usage period.
Figure 9.17
285
Understanding Hyper-V in Windows Server 2012
Figure 9.18
You can install recommended updates in the same manner as important updates.
286
Understanding Hyper-V in Windows Server 2012
Figure 9.19
You should see a message indicating that the cluster role was added successfully.
287
Understanding Hyper-V in Windows Server 2012
5. When the Preview Updates dialog box launches, click the Generate
Update Preview List button (Figure 9.21).
Figure 9.21
6. Windows will produce a list of updates (Figure 9.22). You can click on
anitem to see more detailed information about it.
Figure 9.22
288
Understanding Hyper-V in Windows Server 2012
Applying updates
Updates will be applied according to the schedule that you previously set.
Ifnecessary however, you can apply updates to the cluster on demand by
following these steps:
1. Open the Server Manager.
2. Choose the Cluster-Aware Updating option from the Manage menu.
3. Choose your cluster from the Connect to a Failover Cluster drop-down list
and click Connect if necessary.
4. Click Apply Updates to this Cluster.
5. When the Cluster-Aware Updating Wizard launches, click Next to bypass
the Welcome screen.
6. When the Confirmation screen appears, click the Update button
(Figure9.23). This does not actually perform the update, but rather
schedules an immediate update.
Figure 9.23
7. Verify the success of the operation (Figure 9.24), and click Close.
289
Understanding Hyper-V in Windows Server 2012
Figure 9.24
Make sure that the operation was successful and click Close.
Generating a report
Occasionally it may be useful to create a report as a way of verifying
thepatches that have been deployed to your Hyper-V cluster. The Failover
Cluster Service provides a reporting function that you can use for this purpose.
You can generate a cluster patching report by completing these steps:
1. Open the Server Manager.
2. Choose the Cluster-aware Updating option from the Manage menu.
3. Choose your cluster from the Connect to a Failover Cluster drop-down list
and click Connect if necessary.
4. Click the Generate Report on Past Updating Runs link.
5. When the Generate Updating Run Report dialog box launches, set
thedate range for the report (Figure 9.25).
6. Click the Generate Report button.
290
Understanding Hyper-V in Windows Server 2012
Figure 9.25
When the report completes, the dialog box displays all of the completed runs
within the specified time period. Click on a run to display the updates that
occurred as a part of that run (Figure 9.26). The lower portion of thedialog
box provides statistics on the run that include information such as theamount
of time that the run took to complete and the number of successful
andfailedupdates.
Figure 9.26
The Run Report provides detailed information about the patches that were applied
tothecluster.
291
Understanding Hyper-V in Windows Server 2012
Clicking the Export Report button at the bottom of the screen generates
anHTML version of the report, which contains highly detailed and easytoread
information about thepatches that were applied to the cluster nodes
(Figure9.27).
Figure 9.27
Its a good idea to export the report to HTML because it is much easier toread.
292
Understanding Hyper-V in Windows Server 2012
Chapter 10
Networking
Virtual machines running on a Hyper-V server typically
share the servers physical network adapters. In addition,
Hyper-V supports storage networking through the use of
virtual Fibre Channel. This chapter discusses techniques for
configuring virtual networking and virtual Fibre Channel.
293
Understanding Hyper-V in Windows Server 2012
Virtual machines communicate with one another and with the physical network through
avirtual switch.
When you first install Hyper-V, the setup process asks you which network
adapter you wantto use with Hyper-V. When you make this choice, Hyper-V
creates a virtual switch for the specified network adapter.
Hyper-V also creates a virtual network adapter that the host operating system
uses to communicate with the virtual switch. The virtual network adapter is
assigned the name that was previously used by the physical network adapter.
The only component used by this virtual network adapter is the Hyper-V
Extensible Virtual Switch protocol (Figure 10.2). The virtual network adapter
does not use any of the other common networking components such as TCP/IP.
294
Understanding Hyper-V in Windows Server 2012
Figure 10.2
The virtual network adapter uses only the Hyper-V Extensible Virtual Switch.
The virtual switch itself is also accessible through the Control Panels list of
network connections. It uses the same name as the virtual network adapter,
except that the letter V is appended to the beginning of the adapter name
to indicate that the adapter is a virtual switch. The virtual switch inherits the
physical adapters former IP address configuration.
295
Understanding Hyper-V in Windows Server 2012
Right-click on the host server and choose the Virtual Switch Manager command.
3. When the Virtual Switch Manager opens, make sure that the New virtual
network switch option is selected.
4. Choose the type of virtual switch that you want to create.
5. Click the Create Virtual Switch button (Figure 10.4).
296
Understanding Hyper-V in Windows Server 2012
Figure 10.4
Choose the virtual switch type and click the Create Virtual Switch button.
6. Enter a name for the new virtual switch you are creating (Figure 10.5).
7. Optionally enter notes explaining the virtual switchs purpose.
8. Select the virtual switchs connection type. If you choose to link the virtual
switch to an external network, select the network adapter that the new
virtual switch will be bound to. There is also a checkbox you can select to
control whether or not the management operating system will be able to
access the network adapter.
9. If the virtual switch needs to communicate across a VLAN, select the
checkbox forEnable Virtual LAN Identification for Management
Operating System and specify a VLAN ID.
10. Click OK to create the virtual switch (Figure 10.5).
297
Understanding Hyper-V in Windows Server 2012
Figure 10.5
298
Understanding Hyper-V in Windows Server 2012
Figure 10.6
Choose the virtual switch that you want to assign to the virtual machine and click OK.
Network Adapters
Legacy Network Adapters
Fibre Channel Adapters
299
Understanding Hyper-V in Windows Server 2012
Click Add Hardware, select the Network Adapter option and click Add.
7. Choose the virtual switch that you want the new network adapter to
connect to (Figure 10.8).
300
Understanding Hyper-V in Windows Server 2012
Figure 10.8
Select the virtual switch that the new virtual network should connect to.
8. Click OK.
9. The newly created virtual network adapter will be listed in the virtual
machines Settings page (Figure 10.9).
Figure 10.9
The virtual machines Settings screen now lists two virtual network adapters.
301
Understanding Hyper-V in Windows Server 2012
302
Understanding Hyper-V in Windows Server 2012
Figure 10.10
Select the Enable Bandwidth Management checkbox and specify the minimum
andmaximum bandwidth usage.
303
Understanding Hyper-V in Windows Server 2012
Figure 10.11
VLAN identification
Both virtual network adapters and legacy network adapters support the use of
VLAN identification. Virtual network adapters and legacy network adapters can
be configured with VLAN identification during the adapter creation process or
later. You can configure an existing virtual or legacy network adapter to use a
VLAN by completing these steps:
1. Open the Hyper-V Manager.
2. Right-click on the virtual machine and select the Settings command from
the right-click menu.
3. When the Settings screen appears, select the network adapter to which
you want to assign VLAN identification (Figure 10.12).
4. Select the checkbox for Enable virtual LAN identification.
5. Enter a VLAN identifier number.
6. Click OK.
304
Understanding Hyper-V in Windows Server 2012
Figure 10.12
Select the Enable virtual LAN identifier check box, enter a VLAN ID and click OK.
NIC teaming
The problem with sharing a single physical network adapter among multiple
virtual machines is that the network adapters bandwidth must be shared by all
of the virtual machines that use it. One way to overcome this limitation is to use
NIC teaming.
NIC teaming involves combining multiple physical network adapters into
asingle logical network adapter. The aggregate bandwidth of all the NICs in
the team is available to any physical or virtual server that uses the NIC team.
For example, if you build a team consisting of three 10-gigabit NICs, then
theNIC team would be able to deliver 30 gigabits of bandwidth.
NIC teaming is also useful for fault tolerance. Normally if a physical NIC fails,
all of the virtual machines using the virtual switch that is bound to that NIC will
lose network connectivity. In a teamed environment, however, thefailure of
asingle physical NIC does not cause the entire NIC team to fail. The NIC team
continues to function, but at reduced capacity. It is even possible to designate
a physical NIC within the team as a hot spare (which Microsoft refers to as
a"standby adapter"). Thus, if a NIC fails, thespare can take over so that the
team can continue to operate at fullcapacity.
305
Understanding Hyper-V in Windows Server 2012
NIC teaming is not new in Hyper-V 3.0. Previous versions of Hyper-V allowed
the use of a NIC team, but it had to be created at the hardware level using
specialized NICs that were certified by the hardware vendor for teamed use.
In contrast, Hyper-V 3.0 lets you create a NIC team at the software level. The
physical NICs do not have to meet any special requirements. It is possible to
use a random collection of commodity NICs from multiple vendors.
Windows Server 2012 lets you create NIC teams consisting of up to 32 physical
NICs. For the most part, you can use a NIC team in place of a physical NIC
without issue. The only exceptions are situations in which the following
technologies are used:
SR-IOV
Remote Direct Memory Access (RDMA)
TCP Chimney
These technologies bypass the networking stack and send traffic directly
tothephysical network adapters.
Teaming modes
Before you can build a NIC team, you have to decide which teaming mode you
want the team to use. Windows Server 2012 supports three different teaming
modes including:
Switch Independent This mode allows you to build a NIC team without
having to worry about the configuration of the physical switch. If you
dont know what type of teaming mode to use, then switch independent is
thesafe choice.
Static Teaming Mode This mode is switch dependent and requires
thephysical switch to be configured in a way that identifies the links that
make up the team.
LACP This is a special type of dynamic NIC team that allows you to
reconfigure the team on the fly as needed by adding or removing
physicalNICs.
306
Understanding Hyper-V in Windows Server 2012
Figure 10.13
4. When the NIC Teaming dialog box launches, click the Tasks drop-
down found in the Teams section and choose the New Team option
(Figure10.14).
Figure 10.14
You can create a NIC team by choosing the New Team option.
307
Understanding Hyper-V in Windows Server 2012
Figure 10.15
Assign a name to the NIC team and specify the network adapters that should be included
in the team.
9. Specify the preferred load balancing mode. You can choose between
Address Hash and Hyper-V Port. Address Hash balances network traffic
across all of the NICs in the team and is usually the best choice. Hyper-V
Port matches virtual machines to a specific physical NIC. The Hyper-V Port
method tends to waste a lot of bandwidth; it might saturate some physical
network connections, while leaving others with lots of free capacity.
10. If you have chosen to use a standby adapter then select the adapter you
want to use as a standby spare.
11. Click OK.
Once the NIC team has been created, the Control Panel will still show
theindividual NICs, but it will also display a teamed NIC (Figure 10.17).
Individual NICs within the team should be configured so that the only protocol
bound to the NIC is the Microsoft Network Adapter Multiplexor Protocol
(Figure 10.18). Windows automatically configures teamed NICs correctly, but it
is important to avoid manually altering the NICs configurations. If you need to
assign a static IP address, you should assign it to theNICteam.
Figure 10.17
309
Understanding Hyper-V in Windows Server 2012
Figure 10.18
The NICs making up the team should be configured to use the Microsoft Network Adaptor
Multiplexor Protocol and nothing else.
Note that Hyper-V does not automatically use the newly created NIC team.
Ifyou want Hyper-V to use the NIC team, you will need to bind the NIC team
to avirtual switch (Figure 10.19).
Figure 10.19
You need to bind the NIC team to a virtual switch so that Hyper-V can use the NIC team.
310
Understanding Hyper-V in Windows Server 2012
You may have to enable NPIV support on your Fibre Channel adapter before you can use
Hyper-Vs virtual Fibre Channel feature.
311
Understanding Hyper-V in Windows Server 2012
3. When the Virtual SAN Manager opens, click on World Wide Names
(Figure 10.22).
4. Make any necessary changes to the World Wide Names.
312
Understanding Hyper-V in Windows Server 2012
Figure 10.22
5. Select the New Fibre Channel SAN option and click the Create
button(Figure 10.23).
Figure 10.23
Select the New Fibre Channel SAN option and click the Create button.
6. Enter a name for the new Fibre Channel SAN (Figure 10.24). One common
practice is to name the SAN after the underlying Fibre Channel Host Bus
Adapter.
7. Select the checkbox next to the listing for the Fibre Channel adapter.
8. Click OK.
313
Understanding Hyper-V in Windows Server 2012
Figure 10.24
Enter a name for the new virtual SAN, select the check box for the Fibre Channel adapter
and click OK.
314
Understanding Hyper-V in Windows Server 2012
Figure 10.25
7. Select your virtual SAN from the Virtual SAN drop-down list (Figure 10.26).
8. If you need to modify the World Wide Node Names (WWNNs) or
theWorld Wide Port Names (WWPNs), click the Edit Addresses button
and make any required modifications.
9. Click OK.
315
Understanding Hyper-V in Windows Server 2012
Figure 10.26
Select your virtual SAN from the Virtual SAN drop-down list and click OK.
316
Understanding Hyper-V in Windows Server 2012
Chapter 11
Backing up Hyper-V
317
Understanding Hyper-V in Windows Server 2012
318
Understanding Hyper-V in Windows Server 2012
days the term server backup had reference to a specific disk drive or drive
set. Since everything associated with the server was generally associated
with thephysical disk and each disk was owned by a single server, if you
successfully backed up the disk, you successfully backed up the server.
Of course businesses also had dedicated arrays of disks loosely connected
to servers with the sole purpose being to store data. Here again the central
component was the physical disk, and the backup solutions utilized theexact
same strategy of disk-focused backup, and the strategy worked very
well,until
One of the most significant promises of virtualization is the consolidation of
server workloads onto a single set of hardware. This consolidation promises
decreased capital expenditures and increased utilization percentages. While
both of those are awesome for the business, consolidation also brings with
it a major challenge for the traditional backup software. Virtualization is
NOT centered on the physical disk. The core component of virtualization,
andthecloud, is the virtual machine.
VSS
VSS is not an application. You wont find it on the Start menu. It is a service
and a process with multiple parts used to make image copies of files. In this
particular instance those files are associated with Hyper-V. The VSS process
uses a couple of different components (see Figure 11.1).
319
Understanding Hyper-V in Windows Server 2012
Figure 11.1
VSS Requestor
Volume
Shadow Copy
Hyper-V VSS
Writer
Virtual Machine
320
Understanding Hyper-V in Windows Server 2012
Windows Backup
As in previous versions of Windows Server, Microsoft has included Windows
Backup in Windows Server 2012. This edition of Windows Backup includes
amechanism for VSS-based backups of Hyper-V virtual machines. The tool is
absolutely free. It will successfully complete a VSS full or VSS copy of a virtual
machine. Like previous editions of Windows Backup, there are no frills in
theform of additional options. Here is how it works.
In order to use Windows Backup you must add this feature in the Add Roles
and Features wizard in Server Manager.
Once in place, you can kick off the tool from the desktop icon or from the tools
menu in Server Manager.
Figure 11.2
Backups in Windows Backup are built under the Local Backup menu option in
the Actions pane on the right side of the main screen (Figure 11.2, above). You
can choose Backup Schedule or a Backup Once option from the Actions pane.
This example uses the Backup Once option. This launches the Backup Once
Wizard (See Figure 11.3).
321
Understanding Hyper-V in Windows Server 2012
Figure 11.3
322
Understanding Hyper-V in Windows Server 2012
Next you get to choose what items to include in the backup by choosing
theAdd Items button (Figure 11.5). This launches the dialog shown in
thenextfigure.
Figure 11.6
323
Understanding Hyper-V in Windows Server 2012
Drill down to the desired VM and select it for backup, as shown in the Select
Items dialog (Figure 11.6). There are two other big things to notice on this
screen, indicated by the yellow exclamation icons. First, notice that if you have
used data deduplication on the volume that contains this VM, the data will
be backed up in the unoptimized form, meaning at its original size. Second,
inorder to create the backup, the virtual machine will be placed in saved state
mode, meaning that any workload this VM supports will be at least temporarily
unavailable. After you have selected items to include in the backup, click OK.
Now you can move to the advanced settings for the backup shown in the next
step of the Backup Once Wizard.
Figure 11.7
Click the Advanced Settings button on the Backup Once Wizard (Figure 11.7).
This takes you to the Advanced Settings dialog (Figure 11.8).
324
Understanding Hyper-V in Windows Server 2012
Figure 11.8
In Windows Backup, it is possible to set exclusions of files that you do not want
to include in the backup. The Advanced Settings dialog is also where you are
asked to choose whether you would like to make a VSS copy backup, which will
retain the existing application log files, or make a VSS full backup, which will
truncate the existing log files for the applications (Figure 11.8). After you have
made a selection, click OK to move to the next step.
Figure 11.9
325
Understanding Hyper-V in Windows Server 2012
Next you are given the choice of the type of destination for the backup job.
Will it be housed on locally attached storage or will you use a remotely shared
folder? In this example, the radio button for Local drives has been selected
(Figure 11.9). Click Next to select the backup destination.
Figure 11.10
Now you are given the opportunity of choosing the volume where you want
the job to be stored upon completion, and you are also given summary
statistics about the volume (Figure 11.10). Select the destination and clickNext.
326
Understanding Hyper-V in Windows Server 2012
Figure 11.11
After you have defined the destination, the Backup Once Wizard displays
asummary confirmation page. If the confirmation is correct, you can click
theBackup button to start the process (Figure 11.11).
Figure 11.12
327
Understanding Hyper-V in Windows Server 2012
The backup will proceed until completion and present summary statistics on
status and size of data transferred. In this case, note that the entire 8.35 GB
was transferred (Figure 11.12). There is no compression or deduplication in
Windows Backup. Windows Backup is a general purpose, no frills, VSS capable
backup tool.
Windows recovery
It is often said that the whole point of backup is recovery. In the case of
Windows Backup, the recovery process proceeds as follows.
First, open the Windows Backup application from the tools menu from Server
Manager or the Windows Backup icon on the desktop. Choose Recover from
the Actions pane. This launches the Recovery Wizard.
Figure 11.13
Notice that the information shown in the first step of the Recovery Wizard
indicates that you can recover files, applications, volumes, or the system state;
however, in this case, none of this applies because you are recovering a VM
(Figure 11.13). You can really only recover the VM that you backed up in its
entirety. There just isnt a granular approach to recovering VMs in Windows
Backup. This backup happens to be stored on a volume attached to this server.
Click Next on the wizard to select the backup date.
328
Understanding Hyper-V in Windows Server 2012
Figure 11.14
Here you locate the backup file based on the schedule in which the backup
completed. Select the appropriate date from the calendar to see available
backups in the recoverable items section (Figure 11.14). Click Next on
thewizard to select the recovery type.
Figure 11.15
329
Understanding Hyper-V in Windows Server 2012
Drill down to select the VM backup to restore (Figure 11.16). Click Next on
thewizard to specify recovery options.
Select the desired location for recovery. This is one place where Windows
Backup exceeds expectations as it will allow recovery to an alternate location
oreven make a copy to a folder.
330
Understanding Hyper-V in Windows Server 2012
Figure 11.17
After choosing the recovery option, wait for the process to complete
(Figure11.17).
Windows Backup is a decent utilitarian approach to backup and recovery of
aVM in Hyper-V. It does not perform compression, deduplication or item-level
recovery. Its biggest draw is the fact that it is free. Imagine a scenario where
all the desired functionality were included in a software package while still
maintaining the free price tag.
331
Understanding Hyper-V in Windows Server 2012
Figure 11.18
From the main screen, it is easy to expand the Hyper-V server and see
thevirtual machines. In this case, you can see that the VM is actually up
andrunning (Figure 11.18). Veeam will complete the backup without stopping,
pausing or moving the VM to the saved state mode. Select a VM and choose
Veeam Zip from the ribbon. This launches the dialog shown in the next image.
Figure 11.19
332
Understanding Hyper-V in Windows Server 2012
Figure 11.20
Click the Show Details button (note that this button toggles to Hide Details)
in order to get all the information about each processing backup job
(Figure 11.20). Wait for the backup to complete. The process is simple. It is
important to note that Veeam Backup Free Edition includes the compression
and deduplication functions. In this example, the VM was 8.3 GB and after
compression and dedup, 3.3GB was transferred to the backup repository.
Thetool calculated the rate of compression at 2.4x. Pretty cool!
When you select the Restore button, you will be prompted to select the backup
file of your choice.
333
Understanding Hyper-V in Windows Server 2012
Figure 11.22
After you select the backup file, click Open on the dialog shown above
(Figure11.22).
Figure 11.23
Veeam Backup Free Edition will load the selected backup file and show you its
properties (Figure 11.23). Next, click the Restore button on the .vbk Properties
dialog. Although Veeam Backup Free Edition will restore the full VM, it will also
allow you to restore the VM files, such as the configuration, settings or other
files necessary to run the VM beyond its .vhd or .vhdx file.
Finally, you can choose to restore files from within the Windows OS of the VM,
as shown in the next image. For this example you can choose files from within
the Windows OS.
334
Understanding Hyper-V in Windows Server 2012
Figure 11.24
When you choose to recover files from within the Windows OS, Veeam Backup
Free Edition will mount the operating system and present you with a nicely
structured Windows Explorer-like view of the files (Figure 11.24). At this point
you can simply browse to the files or folders you want to recover and then
right-click and choose Restore from the right-click menu.
Veeam Backup Free Edition is the clear choice for a powerful, easy-to-use,
affordable backup for Hyper-V. Veeam also builds a backup toolset you
can purchase called Veeam Backup & Replication, which adds scheduling
functionality, multi VM job functions and VM replication capabilities.
Veeam Backup Free Edition and the Free Trial Version of Veeam Backup
&Replication can be downloaded at the veeam website www.veeam.com.
335
Understanding Hyper-V in Windows Server 2012
Chapter 12
Automation
andOrchestration
336
Understanding Hyper-V in Windows Server 2012
Introduction
This chapter will be a bit of a departure from previous chapters in that it will
focus less on the basics of Hyper-V features, installation and configuration
and more on how to automate deployment and administrative actions on
theHyper-V platform in an enterprise environment.
With the rise of the dynamic datacenter, cloud computing (private, public
andhybrid cloud), the focus on service-driven IT has led to an increased
focus on advanced automation and self-service, in which IT removes itself
as thebottleneck to request fulfillment through process automation. In this
model, IT becomes a service-driven organization rather than a technology-
driven organization, providing service offerings through a service catalog,
many of which may require little manual effort beyond approval of the request
in a service desk/ticketing system. With that in mind, this chapter focuses less
on Hyper-V in Windows Server 2012 and more on the tools and strategies
available to automate and orchestrate advanced VM, application and virtual
network deployment on Hyper-V.
While PowerShell improvements in v3 secure its place as a go-to toolset in
Hyper-V administration and management, it is not an end-to-end management
solution for the entire virtualization lifecycle. Fortunately, inparallel
todevelopment of Windows Server 2012, Microsoft has been hard at work
updating its System Center 2012 management suite to support the latest
version of its Server OS and hypervisor. In Service Pack 1 for System Center
2012, Microsoft officially added support for management of Windows Server
2012 Hyper-V.
As you saw in chapter 5, PowerShell has a rich set of cmdlets for managing
Hyper-V. While the improvements in PowerShell in Windows Server 2012
for managing Hyper-V are significant, any organization with more than
ahandful of Hyper-V servers will require centralized management capabilities
to effectively manage multiple Hyper-V hosts and VM guests. This is where
theMicrosoft System Center 2012 management suite comes into play
(seeFigure 12.1). The focus in this chapter will be limited primarily to two
System Center 2012 components:
System Center 2012 Virtual Machine Manager (VMM), which is
thestandard for managing Hyper-V in the enterprise
System Center 2012 Orchestrator (Orchestrator), which provides
runbook automation capabilities with out-of-the-box integration with
the other System Center components (including VMM), Active Directory
andthirdparty platforms
These two components together provide powerful automation capabilities
for Hyper-V virtualization deployment management, which you will explore in
depth in this chapter.
337
Understanding Hyper-V in Windows Server 2012
This chapter will spend little time on simple automation, but instead will focus
more on the orchestration of processes. Although it may seem that two terms
are used for the same concept, they are actually quite different. Automation is
essentially advanced scripting, while orchestration requires automation coupled
with decision points based on runtime conditions and business requirements
(such as change management requirements).
Automation is the process of automating a specific task, usually through
ascripting language such as PowerShell. The task typically has one goal,
though it may require several steps to achieve that goal. An example is
bring this server down for maintenance. This may require spinning down
connections to an application, stopping specific processes and then taking
theapplication offlinebut the automation is of a specific task.
Orchestration, on the other hand, is the automation of a complete process. In
the case of cloud computing and IT, this can also be accomplished using scripts
but more often involves the use of APIs. Orchestration links a set of automated
tasks into a single process (IT operational and/or business processes) and may
span multiple devices, applications, solutions and even datacenters. Bring this
server down for maintenance may actually be a single task in a larger process
that is Deploying a new version of an application.
The subtle difference between automation and orchestration is important
primarily because the former is focused on automating a concrete set of steps
normally handled manually but that are performed to a device or component.
The latter often requires participation of intelligent infrastructure components
and decision logic based on runtime conditions in the components involved in
the orchestration (such as resource utilization on Hyper-V hosts as part of the
criteria in determining VM placement). The infrastructure is an active participant
in orchestration.
338
Understanding Hyper-V in Windows Server 2012
Workflows in PowerShell v3
At this point, its likely that you already appreciate the role of PowerShell
in managing Hyper-V. PowerShell definitely plays a role in automating
deployment, administration and maintenance in Hyper-V environments of all
sizes. In PowerShell version 3, the Windows Workflow Foundation engine is
integrated into PowerShell, easing the process of automating long-running,
large-scale, or complex tasks that require multiple steps across multiple
machines. Traditionally Windows Workflow has been a developer-only tool
requiring Visual Studio and a lot of code to create a solution. In the latest
PowerShell release, Microsoft has elevated workflow to an in-the-box solution
that IT Pros can leverage to easily create a solution using their existing
PowerShell scripting skills. Workflow provides direct support for parallel
execution, retry of failed operations, and the ability to suspend and resume
operations. For example, a workflow can detect a problem that requires
manual intervention, notify the operator of this condition and then suspend
operations until the operator corrects the situation and resumes the workflow.
Authoring has been simplified through the extension of the PowerShell
language with the workflow keyword. You can now easily author a workflow
using the tools that ship in all Windows Server 2012 versions. The behavior
of a workflow is different from a simple script or function as it includes a few
more rules. However, if you know how to write a PowerShell function, you
already know most of what you need to know to write a workflow. Authoring
workflows using PowerShell is much easier than working with XAML, and for
most IT Pros it is much easier to understand than Workflow designer tools like
Visual Studio.
Here is a sample PowerShell workflow that provisions five Hyper-V VMs, each
with a differential disk referencing the master disk (goldimage.vhdx). The VMs
will all be placed in the folder specified by the $VMBaseLoc variable, assigned
to the virtual network referenced by $VMNetwork, and finally, each VM
willbestarted.
339
Understanding Hyper-V in Windows Server 2012
340
Understanding Hyper-V in Windows Server 2012
Have you already installed VMM? If not, go back to the Installing VMM
and Orchestrator section earlier in this chapter and refer to the installation
resources provided.
Once you have VMM installed, the next step is to add your Hyper-V server(s)
toVMM for management. Completing these steps installs the VMM
management agent on your Hyper-V host(s).
To add a Hyper-V server to VMM, perform the following steps:
1. From the desktop, launch the VMM Admin Console with a user that is
amember of the VMM Administrators user role
2. From the Navigation pane, select the Fabric workspace, as shown
inFigure12.3.
Figure 12.3 Verifying Your Hyper-V host status in the VMM Admin Console
3. From the ribbon, select Add Resources Hyper-V Hosts and Clusters,
asshown in Figure 12.4. This will launch the Add Resource wizard,
asshown in Figure 12.5.
341
Understanding Hyper-V in Windows Server 2012
342
Understanding Hyper-V in Windows Server 2012
6. On the Discovery scope screen, select the radio button for Specify
Windows Server computers by names and enter the names of
theHyper-V server(s) you wish to add to management in VMM,
asshownin Figure 12.7.
343
Understanding Hyper-V in Windows Server 2012
7. On the Target resources screen, select the checkbox next to the Hyper-V
servers in the list you wish to add to manage from VMM, as shown in
Figure 12.8.
8. On the Host settings screen, select the host group in which you would
like to add your Hyper-V server(s). The All Hosts group is the default value
andwill work for this example, as shown in Figure 12.9.
Figure 12.9 Select the host group for new Hyper-V hosts
344
Understanding Hyper-V in Windows Server 2012
9. On the Migration Settings screen, ensure that the following items are
selected as shown in Figure 12.10:
Turn on incoming and outgoing live migrations
Use Credential Security Support Provider
Use any available network
10. On the Summary screen, review your selection and then click Finish to
add the Hyper-V host to management in VMM. In the Jobs workspace,
you will see a running job titled Add virtual machine host as shown
inFigure12.11.
Figure 12.11 Job details for the Add virtual machine host job
345
Understanding Hyper-V in Windows Server 2012
346
Understanding Hyper-V in Windows Server 2012
3. On the Specify Virtual Machine Identity screen, type the name for
thecloned VM. Popular options here include <VMName>-Clone,
oraname descriptive of the operating system running in the VM. Since
these instructions are for cloning a Windows Server 2012 VM, theexample
uses the name WS2012-Clone. In the Description field, document
thename of the VM you are cloning, as shown in Figure 12.13.
347
Understanding Hyper-V in Windows Server 2012
5. On the Select Destination screen, you will select where the new VM will
be placed. You can place the VM directly on a Hyper-V host (or host
cluster) or deploy it to a private cloud, as shown in Figure 12.15. For this
example, choose to deploy directly to a Hyper-V host.
348
Understanding Hyper-V in Windows Server 2012
Note: You can configure private clouds and deploy VMs to clouds hosted
on Hyper-V in VMM. You can read more about the cloud capabilities in
VMM in How to Create a Cloud in VMM 2012 on the Microsoft site here.
6. On the Select Host screen, Hyper-V hosts available for placement are
shown in order of suitability (availability for placement) and resource
availability (available compute, network and storage resources). If you only
added one Hyper-V host, the process will be unchanged; you will simply
see only the one option for deployment. If the VM cannot be created, you
can find details on the blocking issue on the Rating Explanation tab above
the bottom window on the Select Host screen, as shown in Figure 12.16.
7. On the Select Path screen, you select the location on the Hyper-V host
where the clone will be placed. You can click the Browse button to
choose an alternate storage location if you dont like the default selection,
asshown in Figure 12.17.
349
Understanding Hyper-V in Windows Server 2012
8. On the Select Networks screen, you can change the default adapter
settings, which will match those of the source VM you are cloning by
default. Since you are using a VM template created on the Hyper-V host
you are deploying to, you can accept the defaults on this screen.
350
Understanding Hyper-V in Windows Server 2012
9. On the Summary screen, confirm your settings and then click the Create
button to create the new VM, which will become your first VM template.
The Summary screen is shown in Figure 12.19.
3. On the Select Source page, click From an existing virtual machine that is
deployed on a host, and then click Browse (shown in Figure 12.20). This
launches the Select VM Template Source screen shown in Figure 12.21.
351
Understanding Hyper-V in Windows Server 2012
4. In the Select VM Template Source dialog box, click the VM clone you
created earlier as the VM to convert into a template, click OK and then
click Next.
5. On the VM Template Identity page, provide a name for the VM template
and then click Next.
Important: Under the Bus Configuration heading, make sure to verify that
the virtual hard disk containing the operating system has the Contains
theoperating system for the virtual machine checkbox selected. If this is
not the case, any VM deployments you attempt with this template will fail.
352
Understanding Hyper-V in Windows Server 2012
7. On the Configure Operating System page, you can configure the guest
operating system settings. After you have configured the guest operating
system settings, click Next.
Tip: If you want the VMs you deploy from this template to join an Active
Directory domain automatically, make sure to select Domain / Workgroup
(under the Networking heading) and provide the domain name and
credentials to join the VM to Active Directory, as shown in Figure 12.23.
353
Understanding Hyper-V in Windows Server 2012
8. On the Select Library Server page, click the library server for the VM, as
shown in Figure 12.24, and then click Next.
10. When you click the Browse button, you will be presented with the Select
Destination Folder screen shown in Figure 12.26, where you can select
thefolder in the library share where you want to store the VM template.
Select the folder where you intend to store your VM templates, and then
click OK.
354
Understanding Hyper-V in Windows Server 2012
Note: If you like to keep things tidy, you can click the Explore directory link,
which opens File Explorer to the root of the library, allowing you to create
folders of your own.
11. On the Summary page, you can review your selections to confirm
thesettings for the template, and then click Create.
355
Understanding Hyper-V in Windows Server 2012
The Recent Jobs window will then pop up, and a job named Create Template
will appear as in progress. If you double-click on the running job, you will be
presented with detailed steps of the job in progress as shown in Figure 12.28.
3. On the Select Source page, select the radio button labeled Use an
existing virtual machine, VM template, or virtual hard disk. Click Browse
and select the VM template you just created, as shown in Figure 12.30.
356
Understanding Hyper-V in Windows Server 2012
4. In the Select Virtual Machine Source dialog box, click the appropriate VM
template as shown in Figure 12.31, and then click OK. (Your VM template
name may vary from that in the figure)
7. On the Configure Hardware page, either select the profile you want to
use from the Hardware profile list, or configure the hardware settings
manually. After you have configured the hardware settings, click Next.
8. On the Select Destination page, select the Place the virtual machine on
ahost option as shown in Figure 12.33
357
Understanding Hyper-V in Windows Server 2012
9. On the Select Host page, view the ratings, select the Hyper-V host on
which you want to deploy the VM as shown in Figure 12.34, and then
clickNext.
10. On the Configure Settings page, review the settings for the VM. This is
your opportunity to change placement location (drive letter and path), VM
network settings, VM name, etc. as shown in Figure 12.35
In Locations, either accept the default VM path on the host for storing
theVM files or click Browse to specify a different location. Optionally
select the Add this path to the list of default virtual machine paths
onthehost check box.
358
Understanding Hyper-V in Windows Server 2012
11. On the Add Properties page, you can configure the action to take
when the host starts or stops. To prevent the VM from being migrated
by PRO ordynamic optimization (the VMM features that dynamically
distribute guest load across Hyper-V host clusters), you can also select
theExclude virtual machine from optimization actions check box shown
in Figure12.36. When you are finished with this step, click Next.
12. On the Summary page, confirm the settings and then click Create.
359
Understanding Hyper-V in Windows Server 2012
360
Understanding Hyper-V in Windows Server 2012
361
Understanding Hyper-V in Windows Server 2012
Update Disk
Update Network Adapter
Update VM
Update User Role Property
Update User Role Quota
In the Service Pack 1 release of System Center 2012, several new activities were
added to the VMM 2012 Integration Pack to make automating deployment
of services instances from VMM service templates to Hyper-V even easier.
Thenew activities introduced in Service Pack 1 for Orchestrator 2012 include:
Apply Pending Service Update
Configure Service Deployment
Deploy Service
Get Cloud
Get Service
Get Service Configuration
Get Service Template
Get Tier
Get User Role Quota
Get VM Host
Get VM Network
Get VM Subnet
Monitor VMM Job
Scale Tier In
Scale Tier Out
Set Pending Service Update
Stop Service
Each activity performs a specific action when it is executed (the precise
behavior depends on how the activity is configured by the runbook author).
Once an activity has completed it will output one or more data elements
andtrigger any activities that are linked to it. For example, the runbook in
Figure 12.38 contains an activity that monitors a folder. When a file enters
the folder, the activity triggers a second activity to move the file to an archive
directory (there's a very basic backup approach!), which in turn links an activity
to log an event.
362
Understanding Hyper-V in Windows Server 2012
363
Understanding Hyper-V in Windows Server 2012
Figure 12.40 - Link properties of Service Running link from runbook in Figure 12.39
With the basics out of the way, youre ready to create your first runbook to
deploy VMs to Hyper-V via the web with System Center!
Doing is the fastest path to learning, and the instructions here will help you
build your first runbook. This runbook will allow you (or any self-service user
you authorize) to deploy one or more VMs from Orchestrator, leveraging
theHyper-V VM template youve already created in VMM. The runbook you
will create is shown in Figure 12.39. Now take a look at the process of creating
therunbook.
1. In the Runbook Designer, right-click the Runbooks node and select New
Runbook as shown in Figure 12.41.
364
Understanding Hyper-V in Windows Server 2012
4. Next, drag the following activities onto to the palette in the Runbook
Designer:
From the Runbook Control category, select and drag Initialize Data
onto the palette.
From the SC 2012 Virtual Machine Manager category, select and drag
Create VM From Template onto the palette.
From the Notification category, select and drag Initialize Data onto
thepalette.
Your runbook-in-progress should look similar to Figure 12.44.
365
Understanding Hyper-V in Windows Server 2012
366
Understanding Hyper-V in Windows Server 2012
10. For the VM Name parameter, you will configure the Create VM From
Template activity to derive its value from the VM Name parameter using
what is known as Published Data.
To configure this runbook activity to dynamically populate a field with
published data, right-click in the VM Name field and from the menu,
select Subscribe Published Data, as shown in Figure 12.49. This
opens the Published Data window.
11. In the Activity drop-down, make sure the Initialize Data activity
is selected. In the list of properties, select VMName, as shown
inFigure12.50.
367
Understanding Hyper-V in Windows Server 2012
12. To provide a value for Source Template Name, use the ellipsis to select
theVM template you created earlier.
13. For Cloud Capability Profile, leave the default value.
14. Next, double-click the Send Email (success) activity to configure
properties of this activity.
Subject: To configure the Subject: field (which will serve as the subject
line of the email sent when the VM is provisioned successfully), you
will use a combination of free text and subscribe-to-published-data
technique you learned earlier. The subject line should read:
VM {VM Name from Create VM From Template} created successfully
Recipients: Click the Add button and use the subscribe-to-
published-data technique to configure the runbook to dynamically
add{EmailAddress from Initialize Data}, which will dynamically add
the email address supplied by the user at runtime (Figure 12.52).
368
Understanding Hyper-V in Windows Server 2012
15. In this task, you will modify the link to define the failure path
forrunbooklogic.
Double-click on the link between the Create VM From Template
andthe Send Email (failure) activity.
On the right side in the condition field there is an underlined success
parameter. Click on this parameter and select the failed checkbox.
Select the Options tab.
Click on the black line next to Color and select a red color.
On the General tab, change the link name to VM deployment failed
and then click Finish.
369
Understanding Hyper-V in Windows Server 2012
16. Repeat the process for the success branch of the runbook by double-
clicking on the link between the Create VM From Template and the Send
Email (success) activity. Change the color to green (Figure 12.55) and
thelabel to VM deployed successfully.
17. Click Check In on the navigation bar above the palette to save your work.
And that is it! You have created your first runbook! Now you will test your
runbook to verify that it works using the Runbook Tester.
370
Understanding Hyper-V in Windows Server 2012
Figure 12.56 Launching the Runbook Tester from the Runbook Designer
3. You will be prompted to supply the values defined in the Initialize Data
activity. Supply a valid email address and VM name of your choosing
andthen click OK, as shown in Figure 12.58.
371
Understanding Hyper-V in Windows Server 2012
Your runbook will now run to completion, with the Run VM From Template
activity contacting the VMM server to provision a new VM (using the VM
template you created earlier and specified in this runbook). If the VM is
created successfully, you will receive an email indicating success as shown in
Figure12.59. If VM provisioning fails, you will receive a failure notification.
4. Click Start Runbook in the Actions pane as shown in Figure 12.60. This will
start runbook execution and open the Start Runbook interface.
5. Enter values for EmailAddress and VMName as with the previous test.
6. Select your runbook server from the Available Runbook Server(s) window
and move it to the Selected Runbook Server(s) window as shown in
Figure12.61.
372
Understanding Hyper-V in Windows Server 2012
Figure 12.62 Log and log history tabs in the Runbook Designer
373
Understanding Hyper-V in Windows Server 2012
Double-clicking an activity log entry in the log lets you view the result of
theexecution of that activity. The Details dialog displays the Name, Type,
Status, Start Time and End Time of the activity. If enabled, the Details dialog
also allows you to browse the Published Data of the activity when it was
executed. Use this information when troubleshooting your runbook.
However, because of the overhead and additional database space it consumes,
object-level logging is disabled by default. When youre testing a runbook, you
can turn on object-level logging for insight into the output of each activity in
your runbook.
1. To enable object-level logging, right-click the runbook and select
Properties, as shown in Figure 12.63
374
Understanding Hyper-V in Windows Server 2012
375
Understanding Hyper-V in Windows Server 2012
376
Understanding Hyper-V in Windows Server 2012
377
Understanding Hyper-V in Windows Server 2012
378
Understanding Hyper-V in Windows Server 2012
1. On the New Service Template screen, enter a name for your template
inthe spaces provided. This example uses the name WebApp Service with
a release of 1.0, as shown in Figure 12.68.
379
Understanding Hyper-V in Windows Server 2012
3. In the navigation (left) pane, find the VM template you created earlier
anddrag it onto the machine tier box in the palette of the Service
Designer interface (also shown in Figure 12.69).
4. When you select the machine tier in Service Designer, the tier settings
will be shown at the bottom of the designer interface, as shown
inFigure12.70.
380
Understanding Hyper-V in Windows Server 2012
381
Understanding Hyper-V in Windows Server 2012
8. While still on the OS Configuration tab, under the Roles and Features
heading, select Roles as shown in Figure 12.74. For this example, select
the following roles and role services: Web Server (IIS), IIS Management
Console, Web Server, Application Deployment (and all children), Common
HTTP Features (and all children) and finally, Health and Diagnostics
(andallchildren).
382
Understanding Hyper-V in Windows Server 2012
9. Under Roles and Features, next select the Features node as shown in
Figure 12.75. Select Background Intelligent Transfer Service (BITS).
10. Moving on to the Application Configuration tab, you will see the area
where application first-class deployment and GCEs (remember these?) can
be configured.
11. On the SQL Server Configuration tab, you can configure the settings
for aSysprep SQL instance inside your VM template. In this case you
dont have a Sysprep instance, so leave the defaults and continue
tothenexttab.
383
Understanding Hyper-V in Windows Server 2012
12. On the Custom Properties tab, you can add custom fieldsname/value
pairs that can be used to store values for any of your custom automation,
integration or reporting needs. Accept the defaults and move on
tothenext tab.
13. On the Settings tab, you can configure quota points.
14. On the Dependencies tab, you will see listed any components
this service template requires (e.g., VM templates, OS, hardware
andapplicationprofiles).
15. With your service template configuration now complete, click the View
Script button to view the PowerShell script (created by this wizard), which
will be run to complete the request (if desired), and then click OK.
16. Once youve configured all the settings in your template, click Save and
Validate on the ribbon to ensure the template is configured correctly,
asshown in figure 12.78.
If there are any isssues with your service template, the issues will be
detailed at the bottom of the Service Designer, as shown in Figure 12.79.
If any issues appear, read the explanation provided and make corrections
to the settings in your service template as required and click Save
andValidate once again.
Congratulations, your service template is complete! Next, you will try to deploy
a service instance to your Hyper-V server.
384
Understanding Hyper-V in Windows Server 2012
2. In the Create Service window, click the Browse button and select
theservice template you just created from the window provided, as shown
in Figure 12.81
385
Understanding Hyper-V in Windows Server 2012
3. Provide a descriptive name for your service in the box provided, select
thehost group containing your Hyper-V server in the Destination
dropdown list and click OK, also shown in Figure 12.81.
4. This opens the Deployment Preview shown in Figure 12.82. Here you can
change service settings (e.g., VM name, administrator password). After
making any necessary adjustments, click Refresh Preview in the ribbon to
refresh recommended placement settings.
386
Understanding Hyper-V in Windows Server 2012
6. Youll be prompted one last time with a Deploy service pop-up, where
you will have the opportunity to view the PowerShell (created by this
wizard), which will be used to deploy your service. Click Deploy to initiate
theservice deployment.
Figure 12.84 Final deployment confirmation and the View Script button
387
Understanding Hyper-V in Windows Server 2012
388
Understanding Hyper-V in Windows Server 2012
389
Understanding Hyper-V in Windows Server 2012
390
Understanding Hyper-V in Windows Server 2012
Join the 58,000 organizations who have already modernized their data protection
with Veeam. Download Veeam Backup & Replication today!