VMware tools and PowerCLI part 1

Recently I noticed a few servers did not have VMware tools installed. Needing to see how big of a problem this was, I turned to a few old standbys: RVtools and PowerCLI.

Of course, RVtools was able to provide the info relatively quickly, it was cluttered with extraneous information. I could have chosen to pair down the data by sorting and removing lines, but that seemed like work.

PowerCLI to the rescue!

Having not done this particular task in PowerCLI, the first thing to do was determine how to get the info. A couple of searches later and the VMware tools status was found in the extension data of get-vm: ExtensionData.Guest.ToolsVersionStatus

Great, now to use that data:

So, a relatively simple one liner to find the VMs with no tools installed. Not being one to stop there and putting google to use once again, I found an article that suggested using New_VIProperty to make it easier to understand and use in the future.

Here is the same thing except we are using New-VIProperty to add some clarity and ease to the process:

The New-VIProperty cmdlet is very useful! While certainly not needed in the above examples, it gives us building blocks for more complex scripts. Stay tuned for more on VMware tools and PowerCLI.

Cleaning up files with powershell GUI confirmation

After automating my report last week, I decided I did not need a copy left lying around, so I decided to write a cleanup script.

My first version was very simple, and consisted of just the required code to recurse the directory and delete the files.

It occurred to me that a Yes/No MsgBox to confirm the deletion would be a nice addition. So without further adieu, here is the code.

And here is the output

MsgBox output from script

See how nice that looks? You can use all the Windows GUI Framework in your scripts. I will be designing a script next week that uses several parts of the windows framework to make the script more end user friendly. Keep reading to see my progress and learn how to apply these techniques to your script!

Report Automation with RVtools and Excel

Recently I needed to extract some configuration info from vCenter and email it someone on a semi-regular basis.

They wanted specific information about the hosts and VMs in each vCenter. I figured the easiest way to get the required info was to use Rob de Veij’s excellent RVTools.

To start, I ran RVTools, exported the host tab and the vm tab for 3 vCenters. Not the most efficient way this could be done. So, I made a simple batch file to output the info I wanted.

Now I was left with 6 spreadsheets full of data, most of which I do not need. Again, initially, I deleted the extraneous columns manually. Manual processes are tedious, boring and uninspired… Powershell to the rescue!

Since I had two different sets of output (vms and hosts) I needed two separate scripts to process them (yes I could have combined them, but I really like making things modular) The only difference is in line 2 (columns to keep), so I have only listed one here.

All these scripts do are remove the columns I do not need. A simple loop gets all the files from an array and processes them.

The only thing left is to email the modified Excel files to the person who requested the information. Why not automate that as well? And since we could add or subtract a vCenter, why not have the script e-mail every spreadsheet it finds in the output directory?

With all the pieces in place, the last step is to tie all these disparate scripts together. I created a control script that executes all the other scripts and displays the status as it goes.

And there you have it! All completely automated and no more work anytime I need the report sent.

Something I have considered changing is getting the list of files to process. I could read the directory and put them into the array automatically. Maybe next time…

I’d like to thank all the people who’s code I borrowed (who I promise to credit once I go back though my history and find them)

Removing a Datastore with PowerCLI/Powershell

Another issue that comes along with power outages? Hosts coming back up before their storage… With fiber channel, you can typically reconnect it with a refresh/rescan, but with NFS, they tend to become disconnected.

The fix is to remove and re-add the Datastore (see kb 1005057)

With no way to handle them en masse in the gui and no desire to have to repeat this process in the future, I used Powershell!

Here is the raw script, I will add comments in the near future for those interested.

I chose to run this per cluster

Fixing Greyed out Virtual Machines

As I am sure many of you have, I had an outage recently that caused my hosts to come up before my storage. This resulted in the dreaded invalid or “greyed out” VM.

There are, of course, other ways to recover from this, but I have found this to be the easiest!

Here are the steps to recover from this issue.

1. Determine which host the affected VM(s) are on.

2. SSH to the appropriate host (you will most likely have to enable SSH)

3. Type the following command:

This will list all the greyed out VMs (note it will present you with a numerical vm identifier)

4. Note the four digit ID and add it in place of 0000 in the following command:

If all goes well, in 30-60 seconds the VM will re-register and no longer show as invalid.

My vMetrics

Total Metrics:
44 GHz Total CPU
64 GB Total RAM
3,247 GB Total Disk
2 Host(s)
1 RPs
21 VMs
7 vMotions
Power States:
(3) (18) (0)
8 Physical NICs
8 Virtual PGs
DRS: DRS enabled (Full Auto)
HA: Highly Available
Current Deviation: 0.038
Target Deviation: 0.2
DRS Balance: Load Balanced
HP ProLiant DL360 G5

previous refresh
1325 days, 19 hrs and 36 min.

Recent Comments