{"id":913,"date":"2012-03-05T09:30:04","date_gmt":"2012-03-05T14:30:04","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=913"},"modified":"2012-03-03T09:48:21","modified_gmt":"2012-03-03T14:48:21","slug":"powercli-say-hello-to-ucs-powertool","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/powercli-say-hello-to-ucs-powertool\/","title":{"rendered":"PowerCLI, say hello to UCS PowerTool"},"content":{"rendered":"<p>I&#8217;ve recently been digging into <a href=\"http:\/\/www.cisco.com\/en\/US\/products\/ps10265\/index.html\">Cisco&#8217;s Unified Computing System (UCS)<\/a>.  I wanted a report showing which ESXi host was in each chassis.  I don&#8217;t have a lot of blades (yet) so making this list by hand wouldn&#8217;t have been a lot of work.  However, I had heard about the UCS PowerTool (<a href=\"http:\/\/developer.cisco.com\/web\/unifiedcomputing\/pshell-download\">http:\/\/developer.cisco.com\/web\/unifiedcomputing\/pshell-download<\/a>) and thought this would be a perfect chance to kick the tires.  What I had in mind was something that would look like this:<\/p>\n<pre>\r\nVMHostName              UCSProfileName     UCSBladeSlot\r\n----------              --------------     ------------\r\nesxbl51.bwuch.local     esxbl5-1           sys\/chassis-1\/blade-8\r\nesxbl52.bwuch.local     esxbl5-2           sys\/chassis-2\/blade-8\r\nesxbl53.bwuch.local     esxbl5-3           sys\/chassis-1\/blade-7\r\nesxbl54.bwuch.local     esxbl5-4           sys\/chassis-2\/blade-7\r\nesxbl55.bwuch.local     esxbl5-5           sys\/chassis-1\/blade-6\r\nesxbl56.bwuch.local     esxbl5-6           sys\/chassis-2\/blade-6\r\n<\/pre>\n<p>Unfortunately the ESXi host name I wanted could not be found in the UCS interface.  I was able to find the UUID of the service profile, which maps directly to the UUID in the system.hardware section of Get-View cmdlet for PowerCLI.  Since both of the tools are powershell based it isn&#8217;t very tough to use them together.  (The following code may look long, but that&#8217;s because of a lot of comments.)<\/p>\n<pre><code class=\"language-1\">\r\n# Author: Brian Wuchner\r\n# Date: 2012\/03\/03\r\n# Description: This is a sample inventory report combining information from Cisco UCS Manager with information from VMware vCenter\r\n# The report uses Windows PowerShell and the following modules available from each vendor:\r\n#\tCisco UCS PowerTool: http:\/\/developer.cisco.com\/web\/unifiedcomputing\/pshell-download\r\n#\tVMware PowerCLI: http:\/\/vmware.com\/go\/powercli\r\n\r\n# Define UCS connection details\r\n$ucsSysName = \"ucs.bwuch.local\"\r\n$ucsUserName = \"admin\"\r\n$ucsPassword = \"ucsadminpassword\"\r\n\r\n# Define vCenter connection info\r\n$vcSysName = \"vcenter.bwuch.local\"\r\n\r\n# Import the UCS PowerTool module and the VMware PowerCLI snapin\r\nImport-Module \"C:\\Program Files (x86)\\Cisco\\Cisco UCS PowerTool\\CiscoUcsPS.psd1\"\r\nAdd-PSSnapin vmware.VimAutomation.core\r\n\r\n# The UCSM connection requires a PSCredential to login, so we must convert our plain text password to make an object\r\n$ucsPassword = ConvertTo-SecureString -String $ucsPassword -AsPlainText -Force\r\n$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $ucsUserName, $ucsPassword\r\n\r\n# Create connection to UCS system\r\n$ucsConnection = Connect-Ucs $ucsSysName -Credential $cred\r\n\r\n# Collect the deployed service profiles and convert them to a hash table for easy reference\r\n$serviceProfiles = Get-UcsServiceProfile | where {$_.AssignState -eq \"assigned\"} | select name, PnDn, SrcTemplName, Uuid\r\n$spHT = $serviceProfiles | Group-Object uuid -AsHashTable -AsString\r\n\r\n# Thats all we need from UCS, lets go ahead and logout\r\n$ucsConnection = Disconnect-Ucs\r\n\r\n# Connect to vCenter\r\n$vcConnection = Connect-VIServer $vcSysName # if needed the -user and -password parameters can be passed here, otherwise SSPI is used (current windows credentials)\r\n\r\n# Collect vCenter information on Cisco hardware\r\n$hs = Get-View -ViewType HostSystem -Property Name, Summary.Hardware, Config.Product -Filter @{\"Summary.Hardware.Vendor\"=\"Cisco Systems Inc\"}\r\n\r\n# We are done with vCenter, lets go ahead and logout\r\n$vcConnection = Disconnect-VIServer * -Confirm:$false\r\n\r\n# Put the to lists of information together\r\n$myReport = @() # collection to store all the results\r\n$hs | %{ # loop through the host system vCenter information\r\n\t# create a variable to store the specific Cisco UCS record by UUID\r\n\t$thisCiscoDevice = $spHT[$_.Summary.Hardware.Uuid][0]\r\n\t\r\n\t# populate an object using all the applicable fields needed\r\n\t$myReport += New-Object -Type PSObject -Property @{\r\n\t\tVMHostName = $_.Name\r\n\t\tVMHostVersion = $_.Config.Product.FullName\r\n\t\tCpuModel = $_.Summary.Hardware.CpuModel\r\n\t\tCpuMhz = $_.Summary.Hardware.CpuMhz\r\n\t\tNumCpuPkgs = $_.Summary.Hardware.NumCpuPkgs\r\n\t\tNumCpuCores = $_.Summary.Hardware.NumCpuCores\r\n\t\tUCSBladeSlot = $thisCiscoDevice.PnDn\r\n\t\tUCSProfileName = $thisCiscoDevice.Name\r\n\t\tUCSProfileTemplate = $thisCiscoDevice.SrcTemplName\r\n\t} # end new-object\r\n} # end foreach-object\r\n\r\n# Select a few of the columns in the order we want to see them...display to screen\r\n$myReport | Select VMHostName, UCSProfileName, UCSBladeSlot\r\n<\/code><\/pre>\n<p>For my report needs, I only needed three columns.  I added a handful of additional properties to the $myReport variable for demonstration purposes, but there are many more properties available.  <\/p>\n<pre>\r\nCpuModel           : Intel(R) Xeon(R) CPU E7- 2850  @ 2.00GHz\r\nNumCpuCores        : 20\r\nUCSProfileTemplate : VMware_Blade_5x\r\nUCSBladeSlot       : sys\/chassis-1\/blade-8\r\nCpuMhz             : 1997\r\nUCSProfileName     : esxbl5-1\r\nNumCpuPkgs         : 2\r\nVMHostVersion      : VMware ESXi 5.0.0 build-515841\r\nVMHostName         : esxbl51.bwuch.local\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently been digging into Cisco&#8217;s Unified Computing System (UCS). I wanted a report showing which ESXi host was in each chassis. I don&#8217;t have a lot of blades (yet) so making this list by hand wouldn&#8217;t have been a &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/powercli-say-hello-to-ucs-powertool\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":15,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"predecessor-version":[{"id":929,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/913\/revisions\/929"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}