MSDN Archive Home
Help and FAQs
Code for "Configuration Testing with Virtual Server, Part 2"
All Resource Updates
Change History (all pages)
Because Virtual Server is built upon a set of COM modules, you can completely automate the process of creating and exercising virtual machines. Here we use Windows PowerShell to run the tests.
Virtual Server makes a great platform for testing software. You can create different virtual machines, each with a different combination of operating system and other relevant software. These virtual machines are stored as .vhd files. Suppose you want to write test automation for virtual machines. One approach is to use VBScript to manipulate Virtual Server and this approach is fairly well documented. However before this article, there was very little information available about how to programmatically manipulate Virtual Server using PowerShell.
Virtual Server is built upon a set of COM components and so you can manipulate Virtual Server using any COM aware laguage, in particular VBScript. The primary sticking point to using PowerShell to manipulate Virtual Server is that PowerShell's more stringent security model does not allow PowerShell to directly call the Virtual Server COM functions (VBScript is not restricted in this way). The key is to create a custom PowerShell function which can set security Impersonation.
By the way, the Virtual PC product is a very close cousin to Virtual Server. Both share the same basic code base, however, you can automate Virtual Server but you cannot directly automate Virtual PC.
The code download contains three PowerShell scripts which show you some examples of how to automate Virtual Server.
The examples assume you are using PowerShell v1.0, and have Virtual Server R2, SP1
installed on a machine running Windows Server 2003. The example PowerShell scripts also
assume you have access to a Windows XP SP2 virtual hard disk (.vhd) file created by
Virtual Server. These assumptions represent a lot of overhead, so you may want to simply
examine the PowerShell scripts rather than create their required execution environment.
Microsoft.PowerShell_profile.ps1 - This is a PowerShell startup script which defines a
custom SetImpersonation() function for use by the scripts which manipulate Virtual
Server. The SetImpersonation() function is necessary to get past PowerShell security
barriers which are not present with older script technologies such as VBScript.
createVM.ps1 - This file is a PowerShell script which creates a Virtual Machine. The script
assumes you have an existing .vhd file to use.
exerciseVM.ps1 - This file demonstrates how to configure and execute test automation on a
Virtual Machine using PowerShell. The file copies a test script from the virtual machine host
to the guest machine (Win XP SP2) and executes the test script.
This column is available at:
Nov 18 2008 at 6:29 PM
, version 8
Sign in to add a comment
Configuration Testing ...
Tue Nov 4 2008 at 8:00 AM
More Tags ...
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Manage Your Profile
MSDN Flash Newsletter
© 2008 Microsoft Corporation. All rights reserved.