Cisco UCS PowerTools and PowerShell

Cisco UCS PowerTools and PowerShell

As I mentioned in a previous post, we are upgrading our infrastructure and we are using Dell EMC VxBlock.  So far this upgrade is going fairly smooth, but we are still at the very beginning of the process.  So once I found out that the VxBlock was configured to contain UCS hardware, I began looking to see what Cisco had to offer for PowerShell modules to help manage the new hardware that we are getting.  I found that it’s more than a few modules, but an entire suite of tools called Cisco UCS PowerTools.

Cisco UCS PowerTools Download (click here) *requires Cisco Logon

This suite of tools can also be downloaded via the PowerShell Gallery.  Just need to install all of the modules available.

Find-Module Cisco*
Find-Module Cisco*

Making the Connection to UCS

Once everything has been installed and loaded, you can make the connection to the UCS Manager.

$handle = Connect-Ucs IPAddressofUCSManager 

or

$handle = Connect-Ucs IPAddressofUCSManager -NotDefault

This second command will not add the server that you are connecting to in $DefaultUcs variable.  Why you wouldn’t want to do that, I don’t know yet, but I’m still learning all of these commands.

Get the UCS Information

Because of the way that we configured our VxBlock, we have the VM clusters spread out over the different UCS chassis to provide better availability of the hardware encase of a failure.  The other day I was trying to troubleshoot an issue and I had to search all of the UCS chassis to find the serial number  that matched the blade I was working on.  So I want an easy way to gather the chassis and slot position of the blades along with the serial number.

So I found the cmdlet Get-UcsChassis.  I then ran this cmdlet to find out what information it provided me with so I would know the next step of solving the problem.

Below is the results of the Get-UcsChassis cmdlet.

Get-UcsChassis Results
Get-UcsChassis Results

This is a good start, but this isn’t the information that I’m looking for.  So after checking out the commands I found one that works with the UCS blades.

 get-ucschassis -ucs $handle | Get-UcsBlade 

This command spits out a ton of information.  Most of which isn’t want I want, but I found 2 fields that are ideal, ‘Dn’ and ‘Serial’.  A little bit of tweaking and I’ll be able to use this information in the notes of the blades in vSphere so at a glance I can see where the blade calls home.

Get-UcsBlade Results
Get-UcsBlade Results

Can I Have Your (Serial) Number?

Once I exported this information from the above script to a CSV file, I then needed to gather the serial numbers of the VMhosts.  This is something that I have done before using a host inventory script that I put together a while ago, so I referenced it to get the proper syntax.

$VMhosts = Get-cluster Cluster1, Cluster2, Cluster3, Cluster4, Cluster 5 | Get-VMhost
$report = @()
Foreach ($VMhost in $VMhosts){
$Line = "" | Select Name, SerialNo
$line.Name = $VMhost.name
$cli = Get-vmhost $VMhost | Get-EsxCli
$Line.SerialNo = $cli.hardware.platform.get().serialnumber
$report += $line
}
$Report | Export-Csv C:\scripts\logs\USC_SerialNo.Csv -NoTypeInformation -UseCulture

With this information, I can now finally get to the script that started this whole series of events.  Putting the chassis number and slot location on the VMhost’s custom attributes.

Adding the Address to the VMhosts

Now that I have the 2 outputs, I just need to feed them into a script to add the information to a custom attribute that is generated with the following:

New-CustomAttribute -Name "UCS Location" -TargetType VMHost

Now to populate it with location information.

$UCS_Serials = Import-Csv C:\Scripts\Logs\UCS_SerialNo.Csv
$UCS_Locations = Import-CSV C:\Scripts\Logs\UCS_Location.Csv

#Generates the Hashtable with the VMhost Name and Serial Number
[email protected]{}
foreach($Serial in $UCS_Serials){
     $Serial_HashTable[$Serial.SerialNo]=$Serial.Name
}

#Gets the Serial Number with the location
foreach ($Location in $UCS_Locations){
     $SerialNo = $location.Serial
     $Location = $location.Dn
     If($Serial_HashTable.ContainsKey($SerialNo)) {
          ($VMhostName) = $Serial_HashTable[$SerialNo]
     }
     Get-VMhost $VMhostName | Set-Annotation -CustomAttribute "UCS Location" -Value $Location -Confirm:$false
     #Write-host "The Host is $VMhostName with the location of $location"
}

Once the script finishes, all of the UCS Locations will be populated with the Chassis and Slot location.

UCS Location
UCS Location

Troubleshooting is a breeze when you know where to look for the problem blade.

-Stuart

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.