Cisco UCS PowerTool reporting — get MAC address for each service profile associated with given template 0

The following Cisco UCS PowerTool script illustrates how to get a list of MAC addresses for every service profile that is derived from a specific service profile template.  This is a simple example of how you can report on custom pieces by building a new object dynamically in PowerShell.

This script is useful for creating a report that can be later used to set DHCP reservations, etc.

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
<#
Author: Tim Patterson <tim@pc-professionals.net>
Last Updated: 03/26/2013
Purpose: Document MAC addresses assigned to profiles connected to a service profile template.
Description:
This script is useful for generating a report used to feed into a DHCP server to set reservations, etc.
#>
 
# Make sure you are connected to your UCS system first:
# Connect-UCS -Name <UCS DNS or IP>
 
# Set these:
$service_profile_template = "ESX_Host_AD_Prod_Template"
$interface_name = "eth0"
$path = ".\reports\mac-addr-report-" + $service_profile_template + "-" + $interface_name + ".csv"
 
$serverprofiles = Get-UcsServiceProfile -srctemplname $service_profile_template
 
# Initialize array
$report = @()
 
foreach ($server in $serverprofiles) {
$VNIC = Get-UcsVnic -ServiceProfile $server.name -name $interface_name
 
$obj = New-Object -typename System.Object
$obj | Add-Member -MemberType noteProperty -name Name -value $server.name
$obj | Add-Member -MemberType noteProperty -name MACAddr -value $VNIC.addr
$report += $obj
$obj = $null
}
 
$report
$report | Export-Csv -Path $path -NoTypeInformation