Managing virtual machines with System Center Virtual Machine Manager and PowerShell

Virtualisation is meant to make your life easier. Instead of racks full of humming hot servers, you’ve got much less hardware doing the same work, simplifying your clients’ networks and keeping the power bills down.

Unfortunately that’s only part of the story. Those virtual servers are just as complex to run and manage as any physical server. That’s where a new generation of management tools come in.

Virtual infrastructure needs just as much management as the physical network it replaces, if not more. In the past, when one physical server failed, you’d only lose the applications running on it (and the old ‘one application, one server’ rule kept downtime to a minimum). With virtualisation, three or more servers will be running on that one physical server — so you’ll need to be able to quickly bring them back on line. That’s not the only potential problem. What do you do when one VM starts consuming as much CPU as it can? How can you move the rest of your virtual machines to a less congested machine?

The answer is a new generation of management tools. Microsoft has added virtualisation support to its System Center family of systems management tools, while VMware has launched its own suite of tools under its Virtual Infrastructure brand. There are also virtualisation plug-ins for HP’s OpenView and IBM’s Rational. Most of these tools are targeted at large arrays of virtual servers, though tools from companies like Vizioncore will manage smaller VMware implementations.

If you’re running Microsoft-based networks, the free Hyper-V and Virtual Server hypervisors make an attractive base for any virtual infrastructure. Hyper-V can run as a standalone server or as a role on a Windows Server 2008 system, while Virtual Server is more suited for older hardware and earlier versions of Windows Server. Both come with basic management features, through Web or MMS console snap-ins. If you’re virtualising onto just one sever, the built-in management tools are just about good enough for most everyday operations. It’s when you’re running a larger mix of physical and virtual servers that you want more — and that’s where System Center Virtual Machine Manager (SCVMM) comes in.

Introducing SCVMM
Microsoft launched the first version of System Center Virtual Machine Manager back in 2007. Part of a new wave of management tools, System Center Virtual Machine Manager 2007 was designed to work using Microsoft’s newest management technology, the PowerShell scripting environment. Like Exchange 2007’s Management Console (also built on PowerShell), SCVMM gives you a familiar looking graphical user interface. If you’ve used any of Microsoft’s systems management tools in the past you’ll find its look and feel very familiar. It’s only when you get under the skin that you’ll see the difference. As with many of its server management tools, Microsoft offers a SME version of SCVMM, that can support up to five host servers.

SCVMM is a client-server application. The client management tool runs on any System Center-capable desktop, whether it’s Windows Server or a Vista laptop. The server component runs on a Windows Server host (not necessarily one that’s running a hypervisor), and uses a SQL Server database to store configuration information about the host and guest systems in your network. Software agents on each managed server report back with performance metrics, which can then be viewed in the client application. The SCVMM server can also manage a library of virtual machines, to be deployed as required.

The VM library is an important piece of the SCVMM story, as it’s here you can keep a set of pre-configured virtual servers ready for deployment. Need to add an additional Web server to a Web farm to deal with an unanticipated demand for a client’s ecommerce store? That’s where the library comes in. It’s easy to quickly see where there’s unused processing resource, and then quickly send and activate an image. There’s no need to do any configuration, as SCVMM will do all the work for you.

SCVMM 2007 works with Virtual Server only. The latest version, System Center Virtual Machine Manger 2008 has just been released to manufacturing, so will be available through the channel soon (if you have a MSDN account you can download it now). SCVMM 2008 adds Hyper-V support, so will manage Windows Server 2008 installs — as well as working with VMware’s ESX hypervisor.

PowerShell under the hood
When you drill down into just how the SCVMM client interacts with the server you’ll find the real source of its power – Microsoft’s PowerShell management scripting language. The SCVMM host adds a library of virtualisation-specific PowerShell cmdlets, which you can access and use from your own scripts. The various wizards in the SCVMM client are actually tools for constructing PowerShell scripts. These are then run using the SCVMM server, and can be saved and edited for further use.

If you’re creating a new virtual machine for a server, you can build the appropriate scripts by opening the Hosts section of the SCVMM client, and selecting the host you want to use. In the Actions pane, choose New virtual machine. This launches the New Virtual Machine Wizard.

First choose the source for your VM. If you’ve got existing VMs in your library that you want to deploy, you can browse the library and select an appropriate image. If, instead, you want to build a new VM from scratch, choose the option to create a VM with a blank virtual hard disk; this changes the number of steps.

First give your VM a name and a description. This is especially important if you’re planning on keeping a copy in the SCVMM library. Next you’ll need to configure the elements of your virtual machine. These include the processor type, the amount of memory needed by the virtual server, as well as virtual hard disks and network adapters. You can also define the priority of the VM.

This last option is surprisingly important — as it defines just how CPU resources are allocated by the hypervisor. It’s also an issue fraught with politics. Is Exchange Server more important than accounting’s SQL Server? Just how business critical is an application server, or a file store, or a printer server? Most clients don’t realise just how much of their business depends on their IT systems, and it’s important to make sure that decisions like this are made in concert with your client’s stakeholders.

Once you’ve defined the virtual hardware for your new VM, you can decide whether to install it directly on a host, or store it in the library. If you choose the host route, you can see the available hosts, with a star rating to help you choose which host is best suited for your new VM. If your host is connected to a fibre channel or iSCSI SAN you’ll be able to take advantage of shared storage to make a more portable VM image.

You’ll then need to select a path for where
to deploy the VM image on the host server. The default path is in a public shared virtual machines folder, though you can define alternates. You can also define the user accounts that the host server will use to run a VM, as well as how the hypervisor should handle images when it is stopped. The default is to save the VM state, so it can resume as soon as the host server is restarted.

From wizard to script
The summary screen shows you just what you’re creating — and also offers a View Script button. Click to see the PowerShell script that will actually control how the SCVMM server creates the VM.


Here’s the script we created to make an empty VM on a test server running Virtual Server 2005 R2.
# ------------------------------------------------------------------------------

# Script generated on Tuesday, October 21, 2008 9:38:45 AM by Virtual Machine Manager
# For additional help on cmdlet usage, type get-help <cmdlet name>
# ------------------------------------------------------------------------------
New-VirtualNetworkAdapter -VMMServer localhost -JobGroup 7401a891-3a2f-468a-adc4-a43cbbd7822a -EthernetAddressType Dynamic -VirtualNetwork "External Network (Realtek RTL8139_810x Family Fast Ethernet NIC)"

$CPUType = Get-ProcessorType -VMMServer localhost | where {$_.Name -eq "1-processor 1.20 GHz Athlon MP"}

New-HardwareProfile -VMMServer localhost -Owner "SANDM\administrator" -CPUType $CPUType -Name "Profilea1cbfd6b-fce3-4502-80cc-5dd32459c68c" -Description "Profile used to create a VM/Template" -ProcessorCount 1 -MemoryMB 200 -ExpectedCPUUtilization 20 -DiskIO 0 -NetworkUtilization 10 -RelativeWeight 100 -JobGroup 7401a891-3a2f-468a-adc4-a43cbbd7822a

New-VirtualHardDisk -VMMServer localhost -IDE -Bus 0 -Lun 0 -Size 40960 -Dynamic -JobGroup 9a02bdda-2f60-4e5b-a412-6014d6467d00 -Filename "TestVM_disk_1.vhd"

$VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq ""} $HardwareProfile = Get-HardwareProfile -VMMServer localhost | where {$_.Name -eq "Profilea1cbfd6b-fce3-4502-80cc-5dd32459c68c"}
New-VM -VMMServer localhost -Name "TestVM" -Description "Test VM for IT Expert." -Owner "SANDM\administrator" -VMHost $VMHost -Path "C:\Users\Public\Documents\Shared Virtual Machines\" -HardwareProfile $HardwareProfile -JobGroup 9a02bdda-2f60-4e5b-a412-6014d6467d00 -RunAsynchronously -RunAsSystem -UseHardwareAssistedVirtualization $false -StopAction SaveVM

This corresponds to the information you filled in or selected while following the wizard, and it’s easy to see where you can change the details.
You can now take your copy of the SCVMM generated script, and edit it using your favourite text editor — or a specialist PowerShell tool like Quest’s PowerGui — to use as the basis of an automated VM provisioning application, perhaps taking a list of server names as input, and deploying the same VM on all the servers on the list. Alternatively use it to personalise different VMs for different servers with different capabilities.
The latest version of SCVMM, SCVMM 2008 opens its scripts in Notepad, making it even easier to save out the code you want to work with and reuse it.

This script associates a server with SCVMM as a virtual machine host:
$Credential = get-credential

$VMHostGroup = Get-VMHostGroup -VMMServer localhost | where {$_.Path -eq “All Hosts”}

Add-VMHost -VMMServer localhost -ComputerName “” -Description “” -Credential $Credential -RemoteConnectEnabled $true -RemoteConnectPort 5900 -VmPaths “” -Reassociate $true -RunAsynchronously -VMHostGroup $VMHostGroup
Use this code in a standard set-up script for a new machine. As soon as a new server is connected to a domain it can be made ready to use as a virtual server host – including automatically adding Hyper-V or Virtual Server.
Cmdlets to the rescue
Microsoft ships SCVMM with a library of PowerShell cmdlets. They are a powerful tool for scripting the server component, and automating many common virtualisation functions. To get a complete listing of the standard PowerShell library open a PowerShell console, and type:

Get-Command -PSSnapin VirtualMachineManagerSnapin

Use a tool like Quest’s free PowerGUI, as this gives you one place to write, edit, test and run your scripts.

As administration scripts are powerful tools, you don’t want to store user credentials in a script. You can use PowerShell’s Get-Credential function to collect a username and password each time a script runs, storing them in a variable where they can be used for all the calls in a script. The script-based approach to VM management means you can mix and match PowerShell plug-ins in your scripts. If you need to deploy and manage Exchange Server VMs, to add capacity to a network, you can write a script that deploys a VM, starts it, and then connects Exchange to a domain in the appropriate role. If you were using a GUI this would take quite some time, and several passes through different administration tools. With PowerShell it’s one script that you can fire and forget (checking the logs after it’s finished its run). If you’re deploying fresh images on new hosts you can also include product keys and sysprep information in your scripts, making sure virtual servers are ready to go as soon as they’re turned on. Scripts can also control the hardware profile associated with a VM, making sure that the right resources are associated with the intended server workload.

SCVMM’s PowerShell tools aren’t just for managing VM deployments. Use scripts to make sure that the VM images stored in your clients’ SCVMM libraries are up to date, as well as managing virtual machine snapshots you can use for disaster recovery. You can also automate the process of converting physical servers to virtual, and from one virtual disk format to another, with scripts.

Microsoft is making PowerShell a key component of all its system management tools. With virtualisation becoming more and more important to more and more businesses of all sizes, SCVMM’s scripting capability means that you can build a library of virtual machine management scripts that can be used across all your clients – automating complex tasks, saving you time and increasing your margins.


Show other articles by this author

Share |
Write comment
security image
smaller | bigger



Subscribe and get the magazine in the post before it's online

Subscribe and get access to all of the back issues

To read a sample eMagazine - March 2010



leave When you add a new user and their email address doesn't show up in the Global Address List, work through the tips and suggestions in the ever-useful Exchangepedia Blog:
Bulk-add new users with the script here ( or give existing users mail access ( - this also has details for adding multiple meeting rooms as resources). And when an employee gets replaced, the steps at make it easy to connect the previous user's mailbox to the new user account so that mail for that job role keeps going to the right place. Reject spam with a custom message Just in case the message you're rejecting comes from a real person, you can have Exchange send a less cryptic message that the default error; it will make your customers look more professional. This blog post
explains how - but make sure to keep the 550 error code at the beginning.
read more


Unified communications


The #1 Bestseller for Only 77p