Archive

I recently did a presentation at the South West VMUG on VMware vSphere community (free) health check options. In my presentation I covered some of the options available out there at the moment such as:

vCheck (vSphere plugins)

vGhetto health check script

Miscellaneous PowerCLI / PowerShell options

Starting off the session in style – Intro in mspaint, running under Windows 3.1

The second half of my presentation I dived into a live PowerCLI and PowerShell demo where I demonstrated some PowerCLI basics to get any kind of information out of your vSphere environment using some of the core cmdlets. I demonstrated use of the core PowerCLI cmdlets used for retrieving VM, Host and Datastore information, how to use the pipeline in PowerShell, and taking a look at all properties on any PS object using the Get-Member cmdlet on the pipeline.

After covering these basics, I took a blank vCheck plugin template, and showed how easy it is to create your own custom plugins for vCheck should you find that the existing plugins don’t cover everything you need.

I’ve got a link to download the slides for the presentation below, and hopefully I’ll be able to find a recording of the PowerCLI / PowerShell live demo I did to attach to this post as a follow up.

I was on a vSphere upgrade review engagement recently, and part of this involved checking hardware and existing vSphere VI was compatible with the targeted upgrade.

To help myself along, I created a few PowerCLI scripts to help with information gathering to CSV for the VI parts – such as Host Versions, build numbers, VMware tools and hardware versions, etc… These scripts were built to run once-off, simply either by copy/pasting them into your PowerCLI console, or by running them from the PowerCLI console directly.

They can easily be adapted to collect other information relating to VMs or hosts. To run, just launch PowerCLI, connect to the VC in question (using Connect-VIServer) and then copy/paste these into the console. The output will be saved to CSV in the directory you were in. Just make sure you unblock the zip file once downloaded if you execute them directly from PowerCLI, otherwise the copy/paste option mentioned above will work fine too.

There are three scripts bundled in the zip file:

Gather all hosts under the connected vCenter server and output Host name, Model and Bios version results to PowerCLI window and CSV

Gather all hosts under the connected vCenter server and output Host name, Version and Build version results to PowerCLI window and CSV

Gather all hosts under the specified DC and output VM name and hardware version results to PowerCLI window and CSV

Short and simple scripts, but hopefully they will come in handy to some. As mentioned above, these can easily be extended to fetch other information about items in your environment. Just take a look at the way existing info is fetched, and adapt from there. Also remember that using | gm (get-member) on objects in PowerShell is your friend – you can discover all the properties and methods on PowerShell objects by using this, and use those to enhance your reports/outputs in your scripts.

Quite some time ago I created a PowerCLI function to help me determine VMware Tools versions of queried VMs using PowerCLI. The tools version is returned as a 4 digit number by the vSphere API, and subsequently, so does PowerCLI. This makes determining VMware Tools versions at a glance, a bit of a hassle.

The original function was able to output Tools versions up to ESXi 4.1 u1 or u2, and this week was the first time I had a good use case for this script. I needed more up to date mappings, so I have updated the function to work with VMware tools versions all the way up to ESXi 5.5 now.

PowerCLI at VMworld

Alan Renouf and Luc Dekens led a more advanced PowerCLI session first thing on Thursday morning. There was a good turn up, even after the VMworld Party the night before. This session was of more interest to me, covering off the more advanced features of PowerShell and PowerCLI.

Some of the content I found of interest was:

Event filtering with PowerCLI and the handy GUI/utility Alan/Luc have made to help navigate the events objects. (Event objects in the vSphere API start off on a base object “Event” type, with different derivatives that inherit from this base type for different kinds of events). Interesting for me, as I have actually written an iPhone (iOS) application that uses the VMware SDK to filter out and display information about different kinds of events from your vSphere infrastructure.

VMware Fling called “Web Commander” – this is a web application which appears to be running off PHP as far as I could tell. It gives end users the ability to easily call various PowerShell / PowerCLI scripts from a UI – which is great for operators, or those that are less comfortable playing with a shell 🙂 I can see a good use case for this in just about any environment. It allows users to call scripts and use textboxes to pass parameters over to your scripts.

PowerShell remoting and PSSession creation/disconnection and reconnection to help improve execution times for scripts. Luc showed a nice way to setup a remote machine which can initialise PSSessions, and allow them to be reconnected at a later stage.

New vSAN cmdlets coming out with the newer PowerCLI iterations

You can find more information about the session from Luc and Alan’s personal blogs:

A colleague I work with was looking for a script that would list all disk devices on ESXi hosts that were not set to Round Robin. After this, he wanted to be able to set all of these to the Round Robin Path Selection Policy (PSP). The two tasks can actually be achieved really easily with just a few lines of PowerCLI.

Getting disk devices on all ESX hosts that do not use the Round Robin PSP:

There are quite a few scripts floating around out there that achieve similiar results, but I thought I would do my own take on this task. Below is my full script that offers a simple menu system with two options, one to list/log all current path selection policies on hosts that are not round robin to a timestamped log file, and one to set all path selection policies not round robin, to round robin and log these.

# Description: Offers to either check and log path selection policies not set to RoundRobin, OR, set and log these disk PSPs to RoundRobin
# Author: Sean Duffy
# Web/blog: http://www.shogan.co.uk
# Date: 25/05/2013
## IMPORTANT: Always test scripts in preproduction or your lab before using them live!!
#region UserDefined
# Setup the location of our log files...
# This should be the only custom bit you need to set (the location you want log files to be)
# This will only be used when changing path selection policies
$SetPSPlogfile = "C:\temp\SetPathSelectionPolicy_UpdateScript_Log.txt"
# This will only be used when seeing what path selection policies are in place that are not round robin
$GetPSPlogfile = "C:\temp\GetPathSelectionPolicy_UpdateScript_Log.txt"
#endregion
# Ask for connection details, then connect using these
$vcenter = Read-Host "Enter vCenter Name or IP"
$username = Read-Host "Enter your username"
$password = Read-Host "Enter your password"
$Connection = Connect-VIServer $vcenter -User $username -Password $password
# Grab all ESX hosts on the connection that are either connected, or connected and in maintenance mode
$AllESXHosts = Get-VMHost | Where { ($_.ConnectionState -eq "Connected") -or ($_.ConnectionState -eq "Maintenance")} | Sort Name
# Prompt user with two options - 1) List all disk devices where no roundrobin PSP is set, or 2) Change all disk devices to RoundRobin PSP
Clear
Write-Host "1) Log all disk devices on all hosts where RoundRobin not set." -ForegroundColor Yellow
Write-Host "2) Set and log all disk devices on all hosts where RoundRobin not set, to RoundRobin." -ForegroundColor Yellow
$MenuChoice = Read-Host "Enter your selection (1/2)"
# We could use a switch statement here too, but an if,elseif,else statement is fine in this case...
# Chose option 1
if ($MenuChoice -like "1") {
# Log the username to our log file
$User = $Connection.User
Write "User logged in for reading of PSPs: $User" | Out-File $GetPSPlogfile -Append
Write-Host "Paths not set to RoundRobin for each host will be logged to the $GetPSPlogfile"
Foreach ($esxhost in $AllESXHosts) {
# Write an entry into our log for the host we busy reading PSPs from
$Now = Get-Date
Write "$Now :: Getting paths on $esxhost where not set to RoundRobin" | Out-File $GetPSPlogfile -Append
Write-Host "ESX Host: $esxhost :: Disk devices not set to RoundRobin" -ForegroundColor Cyan
Get-VMhost $esxhost | Get-ScsiLun -LunType disk | Where { $_.MultipathPolicy -notlike "RoundRobin" } | Select CanonicalName,MultipathPolicy | Out-File $GetPSPlogfile -Append
}
Write "------------- End of this run -------------" | Out-File $GetPSPlogfile -Append
Disconnect-VIServer * -Confirm:$false
}
# Chose option 2
elseif ($MenuChoice -like "2") {
# Prompt user with a warning first and ask to confirm to continue as this is a change to policies...
Write-Host "WARNING: You are about to loop through all ESX hosts found and change disks to a PSP of RoundRobin!
Are you sure you want to continue? (Y/N): " -ForegroundColor Yellow -NoNewline
$Answer = Read-Host
# If user answered y, or Y, then continue with the change...
if ($Answer -like "y") {
# Log the username to our log file
$User = $Connection.User
Write "User logged in for change: $User" | Out-File $SetPSPlogfile -Append
# Loop through all ESX hosts
Foreach ($esxhost in $AllESXHosts) {
# Write an entry into our log for the host we are working on along with the current timestamp
$Now = Get-Date
Write "$Now :: Setting PSP for the following current devices on $esxhost to RoundRobin" | Out-File $SetPSPlogfile -Append
Write-Host "ESX Host: $esxhost :: Now setting path selection policy for all disk devices that are not already set to RoundRobin, to RoundRobin" -ForegroundColor Cyan
# Find all disk devices where they are not already set to Round Robin Path Selection Policy and log these to log file
Get-VMHost $esxhost | Get-ScsiLun -LunType disk | Where { $_.MultipathPolicy -notlike "RoundRobin" } | Select CanonicalName,MultipathPolicy | Out-File $SetPSPlogfile -Append
# Find all disk devices where they are not already set to Round Robin Path Selection Policy and set these to RoundRobin
Get-VMhost $esxhost | Get-ScsiLun -LunType disk | Where { $_.MultipathPolicy -notlike "RoundRobin" } | Set-ScsiLun -MultipathPolicy "RoundRobin"
}
Write "------------- End of this run -------------" | Out-File $SetPSPlogfile -Append
Disconnect-VIServer * -Confirm:$false
}
else {
Disconnect-VIServer * -Confirm:$false
Write-Host "Script aborted" -ForegroundColor White
}
}
# Didn't enter a valid choice...
else {
Disconnect-VIServer * -Confirm:$false
Write-Host "Not a valid choice! Exiting script..."
}

The other weekend I managed to get some spare time to do another update to my ESXi 5.0 / 5.1 Host Backup & Restore GUI utility, this time it has been updated to version 1.3. I didn’t post up the changes as it was done by special request from one of my blog readers (thanks Flavio!) However, after receiving more comments with a few others having a similiar issue to what Flavio had, I thought I should definitely post the updated version here, which should hopefully solve the issues some people are seeing.

The changes are based on feedback received in the comments I have received about the utility relating to exceptions received when users in some circumstances try to backup their host configurations. Specifically the exception message “Exception caught: Get-VMHost VMHost with name ‘xxx’ was not found using the specified filter(s).”