Uncategorized

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.

1_3

2_2

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.

3

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.

4

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.

5

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

6

Below is the text of the scripts:7

8

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.