PS1: Mashing UCS host to MAC address via vlookup

21 Sep

This post is more a note to self, but is useful for folks using Cisco UCS enclosure when you need to general a list of hosts against its MAC address on eth0 NIC.

Cisco UCS is notoriously flexible yet complex. If you want a list of physical host names against its MAC address, there is no direct means of exporting that list. You need to get the source from two exports, one from the server export and one from the MAC Identity Management tab in the LAN tab. Then you need perform a vlookup to match each host to its MAC address using “Assigned To” field in th MAC export and “Name” field in the server export.

The macs.csv file looks like this. Notice that all NICs are listed, but you really only want eth0 which is the first NIC used when booting up in PXE

ID,Assigned,Assigned To

This is the hosts.csv file exported from UCS

Name,User Label,Overall Status,Assoc State,Server

Here is the one-line the does a vlookup and outputs the MAC address for the first NIC, i.e. eth0, for each host name.

$mac = @{} ; import-csv .\macs.csv | 
? { $_."Assigned To" -match "eth0" } | 
% { $mac.add(($_."Assigned To" -replace "/ether-eth0"),$ } ; 
import-csv .\hosts.csv | sort-object "User Label" | 
% { "$($mac.get_item($,$($_."User Label".ToLower())" | 
out-file .\mac2hosts.txt -append }
Leave a comment

Posted by on September 21, 2015 in powershell, Scripts


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: