Welcome to TechNet Blogs Sign in | Join | Help
Scripting Virtual Server with PowerShell - CAP-ISO.ps1

Hello Everyone

As promised, attached is the first fo the demo scripts that I used at the “Scripting Virtual Server with PowerShell” session I ran.  I`m not going to go through the whole script but here is an over view and bit more detail on a few key sections.

Script Synopsis

CAP-ISO.ps1 stands for CreateAndPresent-ISO.ps1.  This script can be used to create an ISO file comprising of a given set of files.  This iso is then presented to a guest VM.  I find this particularly useful to run on my laptop with Virtual Server installed.  Essentially this is a quick way of getting files from a host to a guest without having to worry about the network setup. 

Interesting Bits

I should probably give this section a more descriptive title, but you get the idea.  Here’s some of the more interesting sections of the script.

 

Firstly, this script just wraps around an existing command line tool to create the ISO.  This tool is called OSCDIMG.EXE and ships with the Windows Automated Installation Kit (WAIK).  You will need to download the tool, and modify the script to point to its install location.  The WAIK can be downloaded here: http://www.microsoft.com/downloads/details.aspx?familyid=C7D4BC6D-15F3-4284-9123-679830D629F2&displaylang=en

Let’s look at some code.  I don’t want to duplicate what Virtual PC Guy, Ben Armstrong has already written so for a basic guide to scripting Virtual Server with PowerShell go here: http://blogs.msdn.com/virtual_pc_guy/archive/2006/06/13/630165.aspx

So, as Ben Armstrong discussed, you must first have the dll somewhere on the system, and then must reference it from the script.  You also need to be running as admin (and elevated if in Vista).  Here is how to reference the dll.

$result = [System.Reflection.Assembly]::LoadFrom(“$profdir\VSWrapperForPSH.dll”)

 

$profdir is a variable I have created in my profile that points the variable to my profile directory.

I then create a Virtual Server Com Instance like this:

$vs = new-object -com VirtualServer.Application -Strict

 

The next essential part is to set the security on the object.  I do this using a function called setsecurity which can be called anytime.  Here’s the function and an example call to it:

function setsecurity($Object)

{

     $result = [Microsoft.VirtualServer.Interop.PowerShell]::SetSecurity($Object)

    

}

 

$result = SetSecurity $VS

 

I then have to call this function every time I create a new Virtual Server based object.  Whether it’s a VM object, DVD Drive, Hard Disk or any other object I have to set the security once I have created the object.

Have a look through the script and if you have any questions, just post them in the comment section.

For more information on scripting Virtual Server with PowerShell check out Ben Armstrong’s most excellent book, Professional Microsoft Virtual Server 2005, Wrox Publishing.  Check out Ben’s blog for more information on the book:

http://mumblingtomyself.spaces.live.com/blog/cns!64FFB030F5637A64!128.entry

 

Enjoy!

 

BenP

Posted: Tuesday, July 17, 2007 2:05 PM by benp
Attachment(s): cap-iso.ps1

Comments

Scratch The Surface said:

Very usefull script by Ben Pearce on how to quickly make some files/programs available in virtual server

# July 18, 2007 4:34 PM

CoqBlog said:

Ben Pearce a mis en ligne un script issu de sa présentation Scripting Virtual Server with PowerShell

# July 22, 2007 1:24 PM

Loise said:

if somebody needs asoft for this operations go to http://loadingvault.com

it is a very good searcher of rapidshare files

# March 10, 2008 12:12 PM

Rapidshare said:

I completely agree with all that here is told

"So you can find the information on it on my search resource

http://fileshunt.com"

# March 27, 2008 2:03 PM

site index said:

# September 29, 2008 6:20 PM

Rapidshare search engine said:

Download more stuff to your mobile phone  Very usefull rapidshare search engine. In here http://4rapidsearch.com/archive you can see what people search in last hours/days.

# October 7, 2008 6:30 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker