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

cap-iso.ps1

Comments (15)

  1. Anonymous says:

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

  2. Anonymous says:

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

  3. Anonymous says:

    I completely agree with all that here is told

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

    http://fileshunt.com"

  4. Loise says:

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

    it is a very good searcher of rapidshare files

  5. Rapidshare search engine says:

    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.

  6. abdo says:

    very useful rapidshare searh engine too

    http://techebookshare.blogspot.com

  7. Vlad says:

    I would like you to recomend http://filespump.com to look for files you are interested in.

    Now it’s the best file hosting search engine in the web.

    More than 4 000 000 files indexed.

    Try it and i think you will be satisfied with search results.

    Use search string.

  8. Vlad says:

    I would like you to recomend http://filespump.com to look for files you are interested in.

    Now it’s the best file hosting search engine in the web.

    More than 4 000 000 files indexed.

    Try it and i think you will be satisfied with search results.

    Use search string.

  9. bueno says:

    Hi I want to recommend you very useful rapidshare search http://4rapidsearch.com You can find there a lot of new movies, games and music. Enjoy it!

  10. poro says:

    Hi I want to recommend you very useful download files search http://suche-project.eu You can find there a lot of new movies, games and music. Enjoy it!

  11. Marco says:

    Very interesting and clever i found some extra stuff about it http://ddlfrog.com

  12. rightsir says:

    You are right,good topic.you could find useful info by http://rapidmore.com and http://rapidsharedata.com

  13. WebWarez says:

    Great post! http://www.webwarez.net/ is my favourtie website.

  14. Anonymous says:

    Scripting Virtual Server with PowerShell – CAP-ISO.ps1 – Benp’s Guide to Stuff – Site Home – TechNet Blogs