Use Powershell to add virtual machines to Virtual Server

Back to a topic that I know I won't get dinged on.  :)

I was playing arround with the list of available COM ProgID's by using the command in Jeffrey Snover's blog: https://blogs.msdn.com/powershell/archive/2006/06/29/650913.aspx

I ran this command to see the available Program ID's:

dir REGISTRY::HKEY_CLASSES_ROOT\CLSID -include PROGID -recurse | foreach {$_.GetValue("")} | out-file progids.txt

After looking through the file I noticed a very interesting ID called VirtualServer.Application. That sounded promising so I quickly ran the command:

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

I then ran the command $vs to see what I could see...Well the command turned up a bunch of blank properties. So I thought I might have to do some more digging so I did a quick Live Search on VirtualServer.Application and came up with two great blog entries for managing Virtual Server with Powershell:

https://blogs.msdn.com/virtual_pc_guy/archive/2006/06/13/630165.aspx

https://blogs.msdn.com/virtual_pc_guy/archive/2006/06/15/631857.aspx

After creating my COM wrapper and setting my security as described in the Virtual PC Guy's blog entries, I tried my $vs command again and low and behold I had some actual properties.

At this point I wanted to see what I could do with that object so I typed the following command:

$vs | get-member

I quickly noticed a method called RegisterVirtualMachines.  That sounded promising.  I often download gigabytes of virtual machines to play with new technology and it is a royal pain to use the Virtual Server Administration Website to register all of those virtual machines.  So I did another Live Search to see what the parameters were for the RegisterVirtualMachines method and found this reference: https://msdn.microsoft.com/library/default.asp?url=/library/en-us/msvs/msvs/ivmvirtualserver_createvirtualmachine.asp

As you can see there are only two required parameters, the name of the VMC file and the path to the VMC file like this RegisterVirtualMachines("Testmachine.vmc","c:\vms\")

Now I was getting somewhere!  I went ahead and went for the gold and tried this command:

dir . -include *.vmc -Recurse | foreach-object {$vs.RegisterVirtualMachine($_.name,$_.directoryname)}

Boom!  All of my virtual machine's were now registered inside of Virtual Server! 

As you can see with a little bit of research you can take advantage of any COM progID and in a short amount of time start to use it to solve problems.

Comments

  • Anonymous
    July 09, 2006
    Tim - this is exactly the sort of explore/discover/test/solve/communicate loop that we hoped Windows PowerShell would enable.  Thanks for the Post

    Jeffrey Snover [MSFT]
    Windows PowerShell Architect
    Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
    Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx


    PSMDTAG:TYPE:COM:  virtualServer.Application

    PSMDTAG:FAQ: How do I register all my .VMC files a virtual Machines?

    PSMDTAG:PHILOSOPHY: Great example of the explore/discover/test/solve/communicate loop for registring Virtual Machines.