Uncategorized

Fun with PowerShell 2.0 modules: Storage VMotion

One of the most exciting new features coming in PowerShell 2.0 is the addition of PowerShell modules. When you use modules you don’t have to install or register software. I think the most exciting aspect of this is the fact that you deliver functionality purely over the internet without the need to install and update software on client systems.

That’s the idea we have in mind when we decided to publish the VMware PowerShell Community Extensions. Currently the name is a bit more advanced than the idea, since it’s really only 3 cmdlets at the moment, but I personally hope that this will grow into a means for us to deliver functionality quickly and effectively, get feedback in a timely manner, and ultimately make for a much better product. To use the extensions, you’ll need the latest version of the PowerShell 2 CTP, and, of course, the VI Toolkit (for Windows).

Loading the extensions into your session is as simple as these two lines of code:

This code is kind of silly if you think about it, all this really does is download the module from vmware.com to your temp directory and then add it. It would be nicer if you could do something like add-module \\vmware.com\PowerShellExtensions\Extensions.psm1, but we’re not there yet. Also, a bit of full disclosure, this version of the extensions is not signed, yet add-module doesn’t seem to have a problem with it even if your PowerShell execution policy is RemoteSigned. This is likely a bug in the PowerShell 2 CTP. The editing of the module is very restricted (in fact, it’s restricted to just me at the moment,) but if you’re feeling paranoid, you should download the module, examine it to make sure everything looks ok, and only then add it.

One of the cmdlets in the first round of the extensions is SVMotion-VM, which is short for "Storage VMotion a VM". If you don’t know what that means, trust me you’re far from alone. Basically Storage VMotion allows you to move all the files that represent a Virtual Machine from one storage array to another, even if the VM is up and running. This is really useful if you find yourself running low on storage on one array but have plenty on another, or if you buy a fancy new storage array and want to move everything off of your old gear.

The trouble with moving lots of bits around, of course, is that it takes forever. That just means that this is the perfect sort of thing to script. Below is a video that shows exactly that:

Unfortunately the video was a bit too wide for the screen, so for now you’ll just have to settle for this: Video of Storage VMotion through PowerShell

As promised in the video:

There’s a somewhat tricky bit of code in the video that I use to analyze my datastores.

Basically this is just taking advantage of the select cmdlet’s ability to run code blocks to analyze objects in more depth. This is a pretty nice bit of code to see how much data is in use from VMs and where it lives, and also mixes nicely with the export-csv cmdlet for further analysis in Excel. Here is the sample output I made in the video:

Shot

Back to the Community Extensions for a moment.

You may be wondering what to expect from the community extensions. Of course, part of it depends on your feedback, but here’s how I think it will work: The VI Toolkit (for Windows) will contain cmdlets that are well-tested, documented, supported, etc. The community extensions will contain cmdlets that may have little or no testing, may have limited usability in their parameter sets, and likely no documentation or examples. The most useful community extensions will eventually become full, official cmdlets, with all the testing and documentation that comes with it.

Let us know.

Your feedback on this is greatly appreciated, and that includes anything from suggestions about our approach to requests for new cmdlets.

Also, don’t forget that PowerShell 2.0 modules will be just one of many things discussed at tomorrow’s PowerShell Virtual User Group.