Home > Blogs > VMware PowerCLI Blog > Monthly Archives: September 2008

Monthly Archives: September 2008

Changing VMX files just got a whole lot easier.

Ever had one of those moments when someone shows you something that’s a whole lot simpler than what you had in mind? I just had one of those moments. For a long time I’ve wanted the ability to script VMX file changes because there’s a lot of really important and useful stuff you can do with VMX files that you can’t do any other way. With the recent changes to the VI Toolkit Community Extensions (more on that later) I had decided that I was finally close enough to do it, and was going to make it my weekend project (don’t laugh). Out of the blue comes a script from Benjamin Attal, a VMware consultant in France that does exactly what I wanted to do, except his approach is really easy!

It’s also a testament to the depth and power of the VMware API. Adding a key/value pair to every VMX file for every VM is as simple as this:

If every VM is too broad, all you have to do is pass a name (wildcards supported) to get-vm and you can target specific VMs or sets of VMs.

Great, so what do I do with that?

It’s not immediately clear why anyone would care about this. The reason is that there’s some really useful stuff you can do through the VMX file that it is not possible to do using VI Client. I want to focus the rest of this post around two use cases.

The VMX file is a dark, mysterious place, full of hidden surprises. To my knowledge there is no definitive source of information on what options are available and what they do. One piece of useful information can be found in a VMware KB article that discusses how to change VM logging behavior. By changing the "log.rotateSize" and "log.keepOld" keys you can keep more or less log information about your VMs, as your needs dictate. To do that you can either use the script above, changing the $key and $value variables as appropriate, or read the section below for how to do it with the community extensions.

A second really useful thing you can do with VMX files is described by Eric Siebert, who talks about how to change the location where VMware writes snapshots. As I’ve discussed before, snapshots can cause big problems when they are left unchecked. Some people place snapshots on a separate datastore so that if that datastore fills up it won’t interfere with provisioning new systems. Setting the "workingDir" VMX key lets you do that very easily.

Community Extensions

I’ve been meaning to write about how there’s been a whole lot of useful stuff added to the community extensions. I’ll try to update later in the week about some of the new stuff, but for now let’s stick with the VMX theme. We’ve added a cmdlet called set-tkevmx that provides a very simple interface for changing your VMX file. If you download the extension (available on CodePlex) and add it using add-module viToolkitExtensions.psm1, you can then do the stuff mentioned above as easily as this:

This will set the log rotate size on ALL your VMs to 10,000.

This will change every VM you’ve got to store its snapshots and vswp files to an alternative location.

Just for the sake of re-iteration, to run the code above you’ll need PowerShell CTP2 V2, the VI Toolkit for Windows and the VI Toolkit Community Extensions. Enjoy!

Running PowerShell from VI Client with icomasoft PowerScripter

When I was chatting with Glenn last night during the live PowerScripting Podcast he asked when he was going to be able to run PowerShell scripts from inside of VI Client. I asked if he had checked out icomasoft as they have a really nice tool called VI PowerScripter for doing just that.

I had used their Beta 1 plugin, but since they have a Beta 2 now I downloaded it and wanted to give an account of my experiences with Beta 2. I think you’ll see how easy it is to get started and get to the point where you can plug in your own scripts. In this post I want to talk about one of the useful things you can do with icomasoft’s tool.

Snapshots: The silent datastore killer.

Have you ever had a snapshot fill up your datastore because you forgot about it? One of the drawbacks of snapshots is that they get bigger and bigger as you VM writes data. If left unchecked they will keep getting bigger until they finally fill your datastore, making it impossible to do just about anything. It’s happened to me more than once, and from the people I’ve talked to I’m certainly not the only one.

Step 1, of course is to download PowerScripter and run the installer on the same computer where you run VI Client. After you do that, PowerScripter will show up under the Plugins menu.



If you don’t see PowerScripter, make sure it’s enabled by clicking Manage Plugins…

With PowerScripter you define you own PowerShell scripts that run against hosts or against individual VMs. Let’s go through the process of adding some custom scripts.


When you select Script Repository you’ll find yourself in a folder with two subfolders, named HostScripts and VmScripts. To define custom ESX host scripts, place a file inside HostScripts. To define a custom VM script, place it in VmScripts.


When you install, there are no pre-canned VM scripts. You can find samples at icomasoft’s website, but for this example I’ll just add a few of my own.


I added two scripts, one called DeleteAllSnapshot.ps1, one called SnapshotReport.ps1.


Below is the text of the scripts:7


Now let’s head back to the VI Client to start running scripts. Unfortunately the Beta of PowerScripter has a small feature that hopefully gets fixed soon, you’ll need to restart the client. Update: actually to have the scripts show up you can disable then re-enable the PowerScripter plug-in under the Plugins menu.9

After we restart we’re ready to run our scripts.10

This is most useful when you multi-select systems, as show in this screen.11

The report shows us the snapshot’s name, description, parent VM, and, most importantly I think, when the snapshot was made. If a snapshot is too old, chances are it needs to get deleted.12

If you find that a VM has snapshots that need to disappear, you can either remove individual snapshots from the VI Client’s snapshot manager or you can remove them all at once through PowerScripter. Even better, if you need to remove all snapshots on a group of VMs, just multi-select them and you’re nearly done.

Support resources for icomasoft

PowerScripter is just getting started, but icomasoft has a forum where you can go to share ideas and get samples, you should stop by and say hi. Also, even though PowerScripter doesn’t come with any scripts out-of-the-box, there are several sample scripts in their manual that you can drop in and start using. One really useful one is their storage rescan script which allows you rescan all storage across all your hosts with just one click, a huge time saver if you’re still doing it the old-fashioned way.

Videos from VMworld

Thanks to everyone who came out to our Managing VMware with PowerShell session at VMworld 2008! We estimate that there were between 800 and 900 of you, which was way above any of our guesses. Hopefully it was worth everyone’s time.

My slide deck is online, and in addition here are the demo videos we used at the end of the presentation.

VMware and PowerGUI demo at VMworld 2008

Using Invoke-VMScript and the VI Toolkit (for Windows)

If you missed the session, Eric Sloof posted some videos of it, as well as a few interviews as a bonus prize.

I’m really excited about Invoke-VMScript, but it’s worth repeating that this feature is for a future release.

If you’re looking for some of the session not contained in Eric’s videos, look for the full video to be available later on vmworld.com.

And, as always, if you’re interested in using any of the samples contained in the slide deck, get started by downloading the VI Toolkit (for Windows), it is free after all.

Announcing the winners of the VI Toolkit Scripting Contest!

Thanks to everyone for you hard work and contributions to our VI Toolkit Scripting contest.

Now the time has come to announce our winners!

First Prize: Our first prize, a trip to VMworld, goes to LucD for his script, which is a really cool Guest Provisioning System.


I really like Luc’s application because it very easily lets you clone lots of VMs, while giving you control over a lot of the parameters that are frustratingly manual when you try to do them with other VMware tools. Not only that, but you can queue up tens or even hundreds of clone jobs and run them all with the press of a button. This is especially useful since cloning VMs can take a really long time.

Not only that, but as you can see above, this is not just some script meant to be run on a grainy old CRT terminal, it’s a full fledged UI. Speaking of its really cool UI, Bruce Payette, one of the key designers of PowerShell and author of the book PowerShell in Action, had this to say about it: "This is exactly the kind of application we were thinking about when we made PowerShell able to work with WinForms."

Those of us who follow the VI Toolkit for Windows community know Luc quite well, as he has contributed countless great scripts and has really made a difference to a lot of people. So again, congratulations to Luc and we hope to see you in Vegas!

Second Prize: Second prize, a Macbook air, goes to tzamora for his script, VMware Infrastructure Power Documenter. This script makes some really nice reports about VI and outputs them as OpenXML documents that can be read in your favorite word processor or spreadsheet. Here’s a sample.

Here’s what Bruce had to say about this script: "Very nice report generation tool, using OpenXML with templating, Excellent use of “meta” programming with paragraph and sentence functions. Fully parameterized so it can be used from other scripts. Well documented. Both useful and reusable."

Tzamora is something of a newcomer to the VMware PowerShell world, in fact this winning entry was tzamora’s first post on our forums. Congratulations to you, whoever you are!

Third Prize: And Dan Baskette is the proud owner of our third prize, an XBox 360 Elite, for his script powerVDI. Dan’s script can let you create thousands of virtual desktops instantly, consuming the space of one (assuming you have the right hardware).

Here’s what Lee Holmes, author of the Windows PowerShell Cookbook had to say about it: "Automates a very complex scale-out task, and combines a lot of technology (VMWare, Putty, AD, etc) into a single PowerShell task. Offers interactive use, unattended scripting. For high-scale clusters, this would be an enormous time-saver. This script really demonstrates the super-glue nature of PowerShell."

Great work Dan!

Honorable Mentions:

I wanted to make a few honorable mentions because there really was a lot of great stuff contributed. We saw a lot of scripts around reporting, including our second prize winner — obviously this is a big concern for everyone. I wanted to point out my personal favorite reporting script, Alan Renouf’s "Report into MS Word". While Bruce mentioned that Power Reporter was a great example of meta-programming (I’m taking his word on it), I loved Alan’s script because it produces a report with lots of pretty charts and graphs. This is one script everyone should check out.

Hal Rottenberg also nominated slx86’s CloneVDI. As Hal mentions, this script really demonstrates the full power of the VMware Web Services API.

Each honorable mentionee will receive a VMware shirt and a VMware coffee mug.

Congratulations to all our winners, and thanks again to everyone for all your great contributions!

And the winner of the VI Toolkit Scripting Contest is…

going to be announced later today. But since I have your attention, I wanted to mention two blogs that any PowerShell enthusiast should be subscribed to:

First is PeetersOnline.nl by Hugo Peeters. Hugo’s been running a "Helpful Script of the day" feature for a while now, and there’s a lot of really useful stuff there, such as:

And Hugo also talks about our VMware Update Manager cmdlets along with an example that will help you figure out which updates your ESX host is lacking.

Next is Virtu-Al by Alan Renouf. Alan has a really amazing script that will generate a VI report in MS Word, which he entered into our contest. The results are really incredible. In addition to that, Alan has a lot of other PowerShell tips and tricks collected from all over, such as an automated way to change DNS and WINS all over the place.

Anyway, stay tuned for our contest winner announcement!

VI Toolkit (for Windows) Update 1 released.

Some users had reported slowness when using the Get-VM cmdlet. The reason turned out to be an odd quirk in querying some types of network adapters, so many people weren’t affected at all. On the other hand, if you were affected, it was pretty annoying. To address this we’ve released Update 1 of our toolkit. If you’ve had trouble with Get-VM, download it things will go a lot smoother. One user reported that his queries went from more than 5 minutes to just over 10 seconds — a world of difference!

This is the only change we made to the toolkit, so don’t expect lots of new functionality when you download, you’ll have to wait a bit longer for that. If you haven’t had any trouble with 1.0 it’s perfectly fine to keep using it until the next release.

Also, many of you are probably eagerly anticipating the results of our scripting contest. I want to thank everyone for participating and point out that the entries are now open to the public. Check it out, there’s a lot of really great stuff in there.