Report the running UCS firmware versions by ESXi host with PowerCLI/PowerTool 0

After my post yesterday regarding a script that will roll through your vSphere clusters and update the underlying UCS host firmware, I was asked if there was a simple way to generate a report that includes the running (loaded) firmware for those hosts.  The short answer is, YES!

Note:  It is required that you have both the PowerCLI and Cisco PowerTool components installed.  Before running this script it is assumed that you are logged into both the vSphere environment that contains the hosts you want to update, as well as the UCS environment containing the service profiles / hosts to update.  You can download the Cisco PowerTool components here.

Without further ado, here is the script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Script to report on running ESXi host UCS firmware versions.
#
# Assumptions:
#    1. You have already connected to the appropriate vSphere server and UCS environment in PowerShell/PowerCLI.
#    2. The path you enter for the -Path parameter is valid and you have the proper rights to write files there.
#
# Author: Tim Patterson <tim@pc-professionals.net>
# Last Updated: 2014-02-04
# 
 
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True, HelpMessage="ESXi Cluster to Update")]
	[string]$ESXiCluster,
 
	[Parameter(Mandatory=$True, HelpMessage="ESXi Host(s) in cluster to update. Specify * for all hosts.")]
	[string]$ESXiHost,
 
	[Parameter(Mandatory=$True, HelpMessage="Exact path and filename to save CSV output to.")]
	[string]$path
)
 
try {
	$report = @()
	Foreach ($VMHost in (Get-Cluster $ESXiCluster | Get-VMHost | ? {$_.Name -like "$ESXiHost"})) {
		# Correlating ESXi host to UCS service profile:
		$vmMacAddr = $VMHost.NetworkInfo.PhysicalNic | where { $_.name -ieq "vmnic0" }
		$sp =  Get-UcsServiceProfile | Get-UcsVnic -Name eth0 |  where { $_.addr -ieq  $vmMacAddr.Mac } | Get-UcsParent 
 
		# Find the physical hardware the service profile is running on:
		$server = $sp.PnDn
 
		# Retrieve firmware information:
		$firmware = Get-UcsFirmwareRunning -Filter "dn -ilike $server*"
		$adapterfw = $firmware | ?{$_.Type -eq "adaptor" -and $_.Deployment -eq "system"} | Select-Object -ExpandProperty Version
		$cimcfw = $firmware | ?{$_.Type -eq "blade-controller" -and $_.Deployment -eq "system"} | Select-Object -ExpandProperty Version
		$biosfw = $firmware | ?{$_.Type -eq "blade-bios"} | Select-Object -ExpandProperty Version
		$boardcontrollerfw = $firmware | ?{$_.Type -eq "board-controller"} | Select-Object -ExpandProperty Version
		$spfwpolicy = $sp | Select-Object -ExpandProperty OperHostFwPolicyName
 
		$obj = New-Object -typename System.Object
		$obj | Add-Member -MemberType noteProperty -name ESXiHost -value $VMHost.Name
		$obj | Add-Member -MemberType noteProperty -name UCSserviceProfile -value $sp.Name
		$obj | Add-Member -MemberType noteProperty -name ServiceProfileFWPolicy -value $spfwpolicy
		$obj | Add-Member -MemberType noteProperty -name AdapterFW -value $adapterfw
		$obj | Add-Member -MemberType noteProperty -name CimcFW -value $cimcfw
		$obj | Add-Member -MemberType noteProperty -name BiosFW -value $biosfw
		$obj | Add-Member -MemberType noteProperty -name BoardControllerFW -value $boardcontrollerfw
 
		$obj
		$report += $obj
		$obj = $null
	}
	$report | Sort-Object UCSserviceProfile | Export-Csv -Path $path -NoTypeInformation
}
Catch 
{
	 Write-Host "Error occurred in script:"
	 Write-Host ${Error}
	 Write-Host "Finished process at $(date)"
         exit
}
Write-Host "Finished process at $(date)"

Sample Output:

ucs-fw-report