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
$Serial_HashTable=@{}
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

5 thoughts on “Cisco UCS PowerTools and PowerShell”

  1. Hola,
    Need some help.

    With Cisco UCS PowerTool (v 2.4.1.3), is it possible to retrieve/list the decommissioned servers?

    I haven’t found an example of a cmdlet on how to get that information.
    I need to create a report of what and how many servers are decommissioned(disabled).

    The only way im able perform this query is using ssh connection to UCS manager and throwing this command:
    > show server decommissioned

    Thanks in advance for your attention and help.
    Greeetings from México.

    1. Hello Mario,
      I still researching this one, and as soon as I have a valid solution I’ll update you.

      Thanks for your patience with this.

      -Stuart

      1. Ever find a way to Find all Decommissioned Server? I would love to be able to search my 40 UCS Domains for Blades that have been decommissioned but left in the Chassis

          1. Josh,
            I’ve had some time to work out a script that can get the decommissioned servers. To make this work, you will need to use Plink. Also would need to have used putty to make a connection to your UCS domain to have a saved host key for each domain otherwise it will error. I hope this helps and sorry for the long delay in getting this figured out.

            $User = "admin user account"
            $Pswd = "admin password_here"
            $Computer = "IP of your UCS here"
            $plink = "C:\scripts\Applications\plink\plink.exe"
            $plinkoptions = " -v -batch -pw $Pswd"
            
            $cmd1 = "show server decommissioned"
            $remoteCommand = '"' + $cmd1 + '"'
            $command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand
            
            $msg = Invoke-Expression -command $command 
            $msg
            

            -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.