VMware {code} Community
jfmorales
Contributor
Contributor

Easiest Way to Use VIX from PowerShell?

I need to write a Windows PowerShell script to deploy a Linux VM from a template, assign the network adapters to particular networks, start the VM, copy some files to the VM, execute a script on the VM, and copy files back from the VM.  (Note that at the time that we need to copy the files and start the scripts, the NICs on the VM are not yet fully configured, so the VM cannot be reached over the network through SSH.)

My impression is that all these functions can be accomplished through VIX, but it is not obvious how best to use VIX from PowerShell.

1.One of my coworkers has been calling vmrun.exe from PowerShell, but vmrun.exe is actually intended as a command line interpreter for VIX, not as an API for script callers.

2. It appears that the COM interface to VIX should be usable from PowerShell, but I can't find any example scripts that do this. My best hope along these lines is to take the VMScript example from the VIX SDK and try translating it into a PowerShell script.

3. Then I found a blog entry at http://blogs.vmware.com/vix/2008/12/call-vix-more-easily-from-net-plus-powershell-goodness.html that suggests using a wrapper library that someone wrote to make it easy for .NET clients to talk to VIX. But I don't want to get involved in the legalities of redistributing or reimplementing this library, and I also don't understand why it would be better than just using the COM interface to VIX.

I don't have much time to implement this, so I'll have to go with the kludge of calling vmrun.exe unless I can quickly find an alternative.

Thanks for any suggestions! Josephhttp://blogs.vmware.com/vix/2008/12/call-vix-more-easily-from-net-plus-powershell-goodness.html

0 Kudos
4 Replies
admin
Immortal
Immortal

If you are using VIX with vSphere, then you can use VMware PowerCLI -> http://www.vmware.com/go/powercli.

This is a set of tools for managing vSphere that were written from the ground up for PowerShell.  It uses VIX API libraries under the covers to do guest operations.

Hope that helps..

--Matt

jfmorales
Contributor
Contributor

>> If you are using VIX with vSphere, then you can use VMware PowerCLI . . . It uses VIX API libraries under the covers to do guest operations. <<

Thanks, I'm quite confused about the relationship of various VMware products and APIs. I need to connect to a vCenter server to perform actions affecting VMs on ESX hosts. I think vCenter and ESX are considered to be part of vSphere; is that correct?

Also, for some reason I thought that PowerCLI was an interface to one of the other VMware APIs, perhaps to VI. So you're saying it actually calls VIX as well? Or is it that VIX is somehow part of VI?

Sorry for the dense questions. If I can just get started down the correct path, I will have some hope of making progress!

Joseph

0 Kudos
jfmorales
Contributor
Contributor

MattLamantia,

Thanks again.  I've been looking through the PowerCLI documentation, and it does appear to have cmdlets for the various things that I need to do. I'm marking this question as "Answered."

Joseph

0 Kudos
admin
Immortal
Immortal

I would just like to provide a bit more color and have the info present in this thread.

vSphere is (basically) ESX and vCenter Server.

PowerCLI is built on top of both the vSphere API (the web services API) and the VIX API. It does not expose all the features of each, but rather a subset of each. So, it lets you do some of the host and virtual machine management operations from the vSphere API, and some of guest management operations from VIX.

0 Kudos