Skip to Content

vmware

VMware related posts

VMware get-lunpathsetting.ps1

Recently had a need to validate the configured LUN path settings in some of our VMware environments. The prospect of checking them through the VIClient GUI was less then appealing as was checking via command line on each VMhost. So I used VMware's new PowerCLI PowerShell plugin to automate the information gathering. After I did this, my co-worker found a script to set preferences by odd/even Set HBA Preference

We have multiple environments so I tried to make the settings as generic as possible. I added date/time and VIServer to the file name so that it wouldn't get over written if you were running it before and after a configuration change or against different environments.

PowerShell while

From my previous post, I have a nice simple menu figured out and working and that was making my co-worker happy (Happy co-workers more likely to do favors so is a good thing). Our internal patch window for one of our VMware environments was coming up and my co-worker checked on the connected CD-Rom drives from the command line script I found for him so all the guest systems would vmotion properly. Watching over the shoulder I thought I could do a better job of that now.

Two goals.

  1. A menu to determine which of our environments to authenticate against (we have 5).
  2. Offer options to list or disconnect CD-Rom drives without exiting the script.
  3. Happy co-worker

... OK, that's three.

The menu I covered in my previous post with an improvement suggested by Jaykul in the comments.

To go with goal 2, I had a vague memory of 'do .. while'. A quick Get-Help about_ and I see about_while so Get-Help about_while gets me the nice little example I can use to wrap my code in.

PowerShell: A simple menu

Playing with PowerShell and VMware is a lot of fun. We have multiple VMware environments at work, so I longed for a simple menu to stick in front of some scripts I used for various reports against those environments. After some searches, I came up with the Windows PowerShell Tip of the Week archives under 'User Input' from the Script Center. It had some interesting suggestions, some fancy, some to simple for my use. I longed for the old text base menus that were simple to toss together and easy for neophytes to understand.

I had this vague recollection of select .. case in VBScript so on the VBScript to Windows PowerShell Conversion Guide I followed the link to VBScript commands and then to Select .. case.

Here I found a nice little, short article on switch. It looked simple enough and a quick check in my PowerShell console showed that Get-Help About_Switch had some more stuff. I still have to play with it some more but now I have my nice, simple menu to authenticate to the different environments with one script.

The value of digging through an SDK

SDKs are really for programmers but have value for scriptor writers as well. A while ago I found a script to returns the version of VMware tools on guest systems (I didn't write it and wish I'd kept the source link but it does what I needed).

$date=get-date -uformat "%Y%m%d-%H%M%S"; get-vm | % { get-view $_.ID } | select Name, @{ Name="hostName"; Expression={$_.guest.hostName}}, @{ Name="ToolsStatus"; Expression={$_.guest.toolsstatus}}, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} | sort-object name | Export-Csv vmtoolsver_$date.csv

Recently my co-worker did some upgrades to our clusters and ran the script and noted that a large portion of our VMware Tools were behind a version or two. He noted that several of our guest systems did not have the option checked in Edit Settings > Options > VMware Tools Check and upgrade Tools before each power-on' so he sent an email for people to manually check at the next opportunity. I figured there must be a PowerShell script way.

Winning converts to PowerShell through VMWare

We recently upgraded to VMware 3.5. One of the reasons was Update Manager and it's ability to automate vmotion and patching. This was really cool. Turns out, there is a 'gotcha'. You can't automatically use update manager to vmotion a system that has the CD Rom drive connected. My co-worker discovered this on a update of a test environment and discussed this with support, their answer was to check all the systems. As I was going to be helping do this on a Saturday evening, late, I didn't like this answer so much on checking a hundred guest systems manually.

Setting up a PowerShell environment

Having really gotten excited about PowerShell, I have been getting more friends and co-workers to like and use it. So this post is links to downloads and instructions for setting up PowerShell and some of the tools I use so I don't have to repeat myself so much. I freely admit that I am still learning but this will at least get your environment setup quickly (and since we manage VMware servers where I work, links for them are provided).

Syndicate content