System Center Virtual Machine
Manager 2008 R2 RC Scripting Guide
Microsoft Corporation
Published: June 2009
Abstract
This guide provides information about the new and updated cmdlets and parameters in System
Center Virtual Machine Manager (VMM) 2008 R2 RC. The topics in this guide provide sample
scripts that highlight these updates. For information about Virtual Machine Manager 2008
scripting, see Scripting in the System Center Virtual Machine Manager TechCenter library at
http://go.microsoft.com/fwlink/?LinkId=128920.
Contents
What's New in VMM 2008 R2 Scripting ........................................................................................... 5
New and Updated Cmdlets and Parameters in VMM 2008 R2 ................................................... 5
Cmdlets ..................................................................................................................................... 5
Parameters ............................................................................................................................... 5
Live Migration ............................................................................................................................... 7
Virtual Machine Migration Compatibility ....................................................................................... 7
Rapid Provisioning of Virtual Machines ....................................................................................... 8
Quick Storage Migration ............................................................................................................... 8
Maintenance Mode for Hosts ....................................................................................................... 8
RapidProvisionVM.ps1 .................................................................................................................... 9
RapidProvisionVMwithAnswerFile.ps1 .......................................................................................... 11
MaintenanceModeInCluster.ps1 .................................................................................................... 13
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
What's New in VMM 2008 R2 Scripting
The Hyper-V role in Windows Server 2008 R2 includes significant feature improvements. System
Center Virtual Machine Manager (VMM) 2008 R2 leverages these new enhancements by adding
two new cmdlets and several parameters that extend the functionality of the existing VMM
cmdlets.
New and Updated Cmdlets and Parameters in
VMM 2008 R2
The following list summarizes the new and updated cmdlets and parameters in VMM 2008 R2.
Cmdlets
Disable-VMHost
This cmdlet places a VMM host into maintenance mode. For more information, see
Maintenance Mode.
Enable-VMHost
This new cmdlet removes a VMM host from maintenance mode and returns it to service.
For more information, see Maintenance Mode.
Parameters
AllowUnencryptedTransfers
You can use the AllowUnencryptedTransfers parameter to specify that network file
transfers into or out of a library, or into, out of, or within a host group, do not require
encryption. Allowing unencrypted file transfers can improve performance when neither
the source computer nor the destination computer requires encryption. This parameter
can be used with the Set-LibraryServer and Set-VMHostGroup cmdlets.
BlockLMIfHostBusy
You can use the BlockLMIfHostBusy parameter of the Move-VM cmdlet to stop Hyper-V
live migration from attempting to restart a live migration that could not previously start
because the source host or the destination host was already performing a live
migration.
5
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
LimitCPUForMigration
The LimitCPUForMigration parameter limits the processor features for a virtual machine
so that the virtual machine can be migrated to a different physical computer that has a
different version of the same processor as the source computer. Migrating virtual
machines between physical computers with processors from different manufacturers is
not supported. This parameter can be used with the following cmdlets: New-
HardwareProfile, Set-HardwareProfile, New-VM, Set-VM, and Set-Template.
MoveWithinCluster
When you place a host that is a member of a host cluster into maintenance mode using
the Disable-VMHost cmdlet, and you use the MoveWithinCluster parameter, all the
virtual machines that are currently deployed on the host will be migrated to another host
in the same host cluster.
RemoveLibraryStoreSharePath
You can use the RemoveLibraryStoreSharePath parameter of the Set-VMMUserRole
cmdlet to clear the path to the specified library share. This share is used by members of
a self-service user role to store virtual machines or as a repository from which to deploy
stored virtual machines or stored ISO images.
RetainDeletedObjects
When you use the RetainDeletedObjects parameter with the Get-VMMServer cmdlet,
the objects in the cache that are marked for deletion will be preserved. This parameter
is included for users who might develop a user interface.
RetainObjectCache
When you use the RetainObjectCache parameter with the Get-VMMServer cmdlet, the
objects in the cache remain in memory and are not reclaimed by garbage collection.
This parameter is included for users who might develop a user interface.
UseCluster
The UseCluster parameter lets you force the transfer of a virtual machine using
Windows Server 2008 Cluster Migration, even when Hyper-V live migration is available,
when you move a virtual machine using the Move-VM cmdlet. For more information,
see Live Migration.
6
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
UseLocalVirtualHardDisks
The UseLocalVirtualHardDisks parameter specifies that the virtual hard disk file (.vhd)
for a new virtual machine that is created by using the New-VM cmdlet is at a specified
location on the destination host, and that no .vhd files will be copied from the library. For
more information, see Rapid Provisioning of Virtual Machines.
VMNetworkOptimizationEnabled
The VMNetworkOptimizationEnabled parameter enables virtual machine network
optimization detection. This feature improves network performance for virtual machines
with network adapters that support virtual machine queue (VMQ) or TCP Chimney
Offload. VMQ enables creation of a unique network queue for each network adapter.
TCP Chimney Offload enables network traffic processing to be offloaded from the
networking stack. This parameter can be used with the New-VirtualNetworkAdapter,
Set-VirtualNetworkAdapter, New-P2V, and New-V2V cmdlets.
VMWarePortGroup
You can use the VMWarePortGroup parameter to specify a VMware port group.
Live Migration
Hyper-V live migration allows you to migrate a running virtual machine from one node of a
Windows Server 2008 R2 failover cluster to another node in the same cluster without any
perceived downtime for users. When you use the Move-VM cmdlet to move a running virtual
machine that is on a clustered Windows Server 2008 R2 host, VMM will attempt to move the
virtual machine using Hyper-V live migration. If Hyper-V live migration is not available, VMM will
attempt to use Cluster Migration to move the virtual machine. To force VMM to use Windows
Server 2008 Cluster Migration even if Hyper-V live migration is available, use the UseCluster
parameter. For more information about Hyper-V live migration, see \"What's New in Hyper-V\"
(http://go.microsoft.com/fwlink/?LinkId=147115).
Virtual Machine Migration Compatibility
When you use the Get-VMHostRating cmdlet to get the host ratings for a single VMM host that is
running Windows Server 2008 R2 or VMware, the cmdlet performs a direct validation of the
running state of the virtual machine against the host to ensure migration compatibility of the
virtual machine. Performing a direct validation might take several seconds to complete.
Note
If you use the Get-VMHostRating cmdlet to compare a virtual machine against an array
of hosts, the cmdlet will not perform a direct validation of the hosts to produce host
7
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
ratings. To ensure migration compatibility, you should perform a direct validation by
running the Get-VMHostRating cmdlet on each potential target host individually.
Rapid Provisioning of Virtual Machines
To quickly create virtual machines from a template, you can use the UseLocalVirtualHardDisks
parameter of the New-VM cmdlet. This parameter specifies that New-VM use an existing virtual
hard disk file stored locally on the destination host instead of copying a virtual hard disk file from
the library by using Background Intelligent Transfer Service (BITS). Use the Move-
VirtualHardDisk cmdlet to specify the local virtual hard disk file that the virtual machine should
connect to in place of the virtual hard disk file that the template points to. You can also add
another virtual hard disk to the virtual machine by using the New-VirtualDiskDrive cmdlet and
specifying the virtual hard disk. For more information about how to use the
UseLocalVirtualHardDisks parameter, type Get-Help New-VM -detailed at the command prompt.
For a sample script about how to use rapid provisioning to create a new virtual machine, see
RapidProvisionVM.ps1 or RapidProvisionVMwithAnswerFile.ps1.
Quick Storage Migration
For a Windows Server 2008 R2 host or a VMware Storage VMotion-capable host, you can use
the Move-VirtualHardDisk cmdlet together with the Move-VM cmdlet to migrate a running virtual
machine and its files (Windows-based .vhd files or VMware-based .vmdk files) to a different
storage location on the same host or on a different host, with minimal or no service outage. For
more information about how to move a running virtual machine and its files, type Get-Help Move-
VM –examples at the command prompt.
Maintenance Mode for Hosts
In VMM 2008 R2, you can start maintenance mode for a Windows-based host anytime you need
to perform maintenance tasks (such as applying updates or replacing a physical component) on
the host.
When you use the Disable-VMHost cmdlet to place a Windows Server 2008 R2 clustered host
into maintenance mode, you can choose one of the following:
If live migration is available, evacuate all highly available virtual machines to other hosts on
the same cluster. Virtual machines that are not highly available are placed into a saved state.
Place all virtual machines on the host into a saved state.
When you place a stand-alone Windows-based host or a host within a Windows
Server 2008 cluster into maintenance mode, VMM automatically places all the virtual machines
into a saved state.
While in maintenance mode, VMM automatically does the following:
It blocks virtual machine creation operations on the host.
8
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
It excludes the host from the host ratings during placement.
It sets the value for the host state property to In Maintenance Mode.
For more information about Disable-VMHost, type Get-Help Disable-VMHost –detailed at the
command prompt.
After you have used the Enable-VMHost cmdlet to remove the host from maintenance mode and
to place it back in service, VMM does the following:
It allows virtual machine creation on the host.
It includes the host in the host rating calculations during placement.
It sets the value for the host state property back to the host's current state.
However, VMM does not automatically move highly available virtual machines back onto the host,
and it does not restart any of the virtual machines that were placed in a saved state. For more
information about Enable-VMHost, type Get-Help Enable-VMHost –detailed at the command
prompt. For a sample script about how to place clustered hosts into maintenance mode, see
MaintenanceModeInCluster.ps1.
RapidProvisionVM.ps1
To quickly create virtual machines from a template, you can use the UseLocalVirtualHardDisks
parameter of the New-VM cmdlet. This parameter specifies that New-VM use an existing virtual
hard disk file stored locally on the destination host instead of copying a virtual hard disk file from
the library by using Background Intelligent Transfer Service (BITS). Use the Move-
VirtualHardDisk cmdlet to specify the local virtual hard disk file that the virtual machine should
connect to in place of the virtual hard disk file that the template points to.
Before you use the script in this topic, ensure that the following actions have been completed:
1. You have created a template from a virtual machine that contains the operating system and
any desired applications, and you have configured the template to meet all user
requirements. Optionally, the virtual machine from which the template is created can have
Integration Components installed. Confirm that the template:
Uses the virtual hard disk file that is attached to the source virtual machine from which
the template was created.
Contains updated Hardware Configuration settings.
Contains updated OS Configuration settings, such as a product ID.
2. You have copied the generalized virtual hard disk file to the destination host. This location
needs to be specified in the script. You can copy the virtual hard disk file directly to the host
using a command such as robocopy or xcopy. Or, within a storage area network (SAN)
environment, you can use a SAN technology, such as one of the following:
Snapshot of an existing logical unit number (LUN)
Clone of an existing LUN
9
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
You can also use this script to create a virtual machine by using a template with an embedded
answer file. For more information, see RapidProvisionVMwithAnswerFile.ps1.
Disclaimer
Before you run the following script, replace the values for the name of the VMM server, the
template name, the name of the destination host for the virtual machine, the path of the local
virtual hard disk file, and the path where you want to create the virtual machine.
# Filename: RapidProvisionVM
# Description: Creates a new virtual machine using a virtual hard disk
# that has been generalized by Virtual Machine Manager (VMM) and
# that is stored locally on a Hyper-V host.
# Connect to the VMM server.
$VMMServer = Get-VMMServer \"VMMServer01.Contoso.Com\"
# Define the variables.
$JobGroupID = [Guid]::NewGuid().ToString()
$Template = Get-Template | where {$_.Name -eq \"Template01\"}
$VMHost = Get-VMHost | where {$_.ComputerName -eq \"VMMHost01.Contoso.Com\"}
$VMName = \"VM01\"
# Use the Move-VirtualHardDisk cmdlet to point to the local virtual hard disk on the
host.
Move-VirtualHardDisk -IDE -BUS 0 -LUN 0 -Path \"c:\\VHDs\\LocalVHDFile.vhd\" -JobGroup
$JobGroupID
# Use the New-VM cmdlet with the –UseLocalVirtualHardDisks parameter to create the
# virtual machine and to specify that the local virtual hard disk file should be used.
New-VM -Name $VMName -Path \"D:\\VirtualMachinePath\" -Template $Template -VMHost $VMHost -
ComputerName $VMName -JobGroup $JobGroupID -UseLocalVirtualHardDisks -RunAsynchronously -
JobVariable \"NewVMJob\"
# Display the job progress.
10
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
While ($NewVMJob.status -eq \"Running\")
{
Write-Progress -activity \"Creating new virtual machine\" -status $NewVMJob.CurrentStep
Start-Sleep -seconds 5
}
RapidProvisionVMwithAnswerFile.ps1
The RapidProvisionVM.ps1 topic introduced a script that you can use to create a virtual machine
that connects to an existing virtual hard disk (.vhd) file stored locally on a destination host. You
can also use this script to create a virtual machine from a template that contains an embedded
answer file and Integration Components. Because Integration Components are already installed,
use the SkipInstallVirtualizationGuestServices parameter of the New-VM cmdlet in the script to
specify that New-VM should not attempt to install Integration Components after creating the
virtual machine.
Before you use the script, follow these steps:
1. Create a virtual machine that contains an operating system, and configure all the settings to
meet user requirements. Optionally, you can install Integration Components; however, this
may not be necessary, depending upon your operating system.
2. Create an answer file, and store it in the file system of the virtual machine that contains the
guest operating system. The answer file should include the following:
Product key
Credentials with permissions to join a domain
The computer name wildcard character (*), which allows the computer name to be
randomly generated
3. Generalize the guest operating system using the Sysprep tool, and then shut down the virtual
machine.
4. Copy the generalized .vhd file to the destination host. This location needs to be specified in
the script. You can copy the virtual hard disk file directly to the host using a command such
as robocopy or xcopy. Or, within a storage area network (SAN) environment, you can use a
SAN technology, such as one of the following:
A snapshot of an existing logical unit number (LUN)
A clone of an existing LUN
5. Create a new template from a .vhd file (this can be any .vhd file because it is a placeholder).
When you create the new template:
11
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
On the Configure Hardware page of the New Template Wizard, update the settings as
necessary.
On the Guest Operating System page of the wizard, select Customization not
required in the Guest operating system profile list.
Before you run the following script to create a virtual machine, replace the values for the VMM
server name, the template name, the name of the destination host for the virtual machine, the
path of the local virtual hard disk file, and the path where you want to create the virtual machine.
Disclaimer
# Filename: RapidProvisionVMsWithAnswerFile.ps1
# Description: Creates a new virtual machine using a virtual hard disk (.vhd)
# that has an embedded answer file that has been generalized by Virtual
# Machine Manager (VMM), and that is stored locally on a Hyper-V host.
# Connect to the VMM server.
$VMServer = Get-VMMServer \"VMMServer01.Contoso.Com\"
# Define the variables.
$JobGroupID = [Guid]::NewGuid().ToString()
$Template = Get-Template | where {$_.Name -eq \"Template01\"}
$VMHost = Get-VMHost | where {$_.ComputerName -eq \"VMMHost01.Contoso.Com\"}
$VMName = \"VM01\"
# Use the Move-VirtualHardDisk cmdlet to point to the local .vhd file on the host.
Move-VirtualHardDisk -IDE -BUS 0 -LUN 0 -Path \"C:\\VHDs\\LocalVHDFile.vhd\" -JobGroup
$JobGroupID
# Use the New-VM cmdlet with the –UseLocalVirtualHardDisks parameter to create the
# virtual machine and to specify that the local .vhd file should be used.
# Additionally, use the -SkipInstallVirtualizationGuestServices parameter because
# Integration Components are already installed in the .vhd file.
12
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
New-VM -Name $VMName -Path \"D:\\VirtualMachinePath\" -Template $Template -VMHost $VMHost -
JobGroup $JobGroupID -UseLocalVirtualHardDisks -SkipInstallVirtualizationGuestServices -
RunAsynchronously -JobVariable \"NewVMJob\"
# Display the job progress.
While ($NewVMJob.status -eq \"Running\")
{
Write-Progress -activity \"Creating new virtual machine\" -status $NewVMJob.CurrentStep
Start-Sleep -seconds 5
}
MaintenanceModeInCluster.ps1
In System Center Virtual Machine Manager (VMM) 2008 R2, you can start maintenance mode for
a Windows-based host anytime you need to perform maintenance tasks (such as applying
updates or replacing a physical component) on the host.
When you use the Disable-VMHost cmdlet to place a Windows Server 2008 R2 clustered host
into maintenance mode, you can choose one of the following methods:
Use the MoveWithinCluster parameter to evacuate all running highly available virtual
machines to other hosts on the same cluster using live migration. Virtual machines that are
not highly available are placed into a saved state.
Place all running virtual machines on the host into a saved state.
While in maintenance mode, VMM automatically does the following:
It blocks virtual machine creation operations on the host.
It excludes the host from the host ratings during placement.
It sets the value for the host state property to In Maintenance Mode.
After you complete maintenance activities on the host, use the Enable-VMHost cmdlet to remove
the host from maintenance mode and to place it back in service. When the host is placed back in
service, VMM does the following:
It allows virtual machine creation on the host.
It includes the host in the host rating calculations during placement.
It sets the value for the host state property back to the host's current state.
However, VMM does not automatically move highly available virtual machines back onto the host,
and it does not restart any of the virtual machines that were placed in a saved state.
13
[This is prerelease documentation and is subject to change in future releases. Blank
topics are included as placeholders.]
The following script gets all the VMM hosts in a cluster, sequentially places each host into
maintenance mode using the MoveWithinCluster parameter, pauses for maintenance activities,
and then restarts the host.
Disclaimer
# Filename: MaintenanceModeInCluster.ps1
# Description: Sequentially places each host in a cluster into maintenance mode.
# The MoveWithinCluster parameter indicates that all running highly
# available virtual machines are moved to other hosts in the cluster
# using live migration. Virtual machines that are not highly available
# are placed into a saved state. The script pauses for maintenance
# activities and then places the host back into service.
# Connect to the VMM server.
$VMMServer = Get-VMMServer -ComputerName \"VMMServer01.Contoso.com\"
# Get the hosts in the cluster.
$Cluster = Get-VMHostcluster -Name \"Cluster01\"
$VMHosts = Get-VMHost -VMHostCluster $Cluster
# Sequentially place each host in the cluster into maintenance mode,
# pause the script for maintenance activities, and then place
# the host back into service.
Foreach ($VMHost in $VMHosts)
{
Write-Host \"Placing host\" $VMHost \"into maintenance mode.\"
Disable-VMHost $VMHost -MoveWithinCluster
Start-Sleep \"60\"
Write-Host \"Placing host\" $VMHost \"back into service.\"
Enable-VMHost $VMHost
}
14
This guide provides information about the new and u more
This guide provides information about the new and updated cmdlets and parameters in System Center Virtual Machine Manager (VMM) 2008 R2 RC. The topics in this guide provide sample scripts that highlight these updates. For information about Virtual Machine Manager 2008 scripting, see Scripting in the System Center Virtual Machine Manager TechCenter library at http://go.microsoft.com/fwlink/?LinkId=128920. less
0 comments
Post a comment