Home > Blogs > VMware PowerCLI Blog


Audit and Manage ESXi Hosts with PowerCLI

It’s not enough in this day and age for administrators to oversee their virtual environments. Increasingly I hear more about the need for updating the ESXi hosts’ drivers and firmware during maintenance windows. I get it, I completely understand this need. So how does an admin keep up on what hardware all of his VMs are running on? What if you need to check the hardware to compare it against the Hardware Compatibility List for a new version?

We’ve made this much easier! Read on!

Introducing Two New Cmdlets

In PowerCLI 6.0 R2 we introduced two new cmdlets to help admins have visibility into the physical hardware their virtual environments are running on.

Get-VMHostHardware

Get-VMHostHardware allows users to query their ESXi hosts and return specific information about each machine. Some of the key information returned includes:

  • VMHost Name
  • Manufacturer
  • Model
  • Serial Number
  • Asset Tag
  • BiosVersion
  • CPU Model
  • CPU Count
  • CPU Core Count Total
  • Mhz Per CPU
  • NicCount
  • and more…

vmhosthardware

This can be very beneficial when running a report on the hardware the virtual environment is running on. Information from this cmdlet, like the Bios Version, can be very helpful when planning the next maintenance window for specific hosts. Now you have two options for determining which hosts need to be updated. First, exporting all results to CSV and then filtering on BIOS version or other property. Second, modify the PowerCLI command to filter results to return exactly the data that you want to see. For example, you may use the following code to bring back each unique BIOS Firmware version across your hosts:

HardwareSorted

We use the ConnectionState property because the Get-VMHostHardware cmdlet cannot query against a disconnected host, so rather than seeing an error for any host that is not connected, we take care of it at this stage.

The additional information provided by this cmdlet will allow you to verify CMDB data as well as feed reports back to CMDBs or other groups in your company.

Get-VMHostPciDevice

Want a cmdlet that will return all PCI Devices on your ESXi Host? Look no further! The new Get-VMHostPciDevice cmdlet will return all the information you ever wanted about your ESXi Host devices. It operates just like the previous cmdlet so you will need to make sure that the hosts are powered-on and connected before running this cmdlet otherwise it will return an error for any host not in this desired state. I find it easiest to export this information to either a CSV or use Out-GridView to pull this information into a nicely formatted window to look through. The code below can be used to bring back all PCI Device information on all ESXi Hosts in your vCenter

image

You could take this information and export it to CSV and save it for future reference or support.

To learn more about these two cmdlets, use the Get-Help cmdlet to see examples or read more about them in the online cmdlet reference here.

Have you updated to PowerCLI 6.0 R3 yet? Why not? Did you know it supports all the way back to vCenter Server 5.0? Download it today from here and gain the latest benefits.

This entry was posted in ESX, Hardware and tagged , on by .
Brian Graf

About Brian Graf

Brian Graf is a well-known VMware evangelist in the IT community. Over the past 5 years, Brian has done Technical Marketing for PowerCLI Automation and ESXi Lifecycle, Product Management of vCenter Distributed Resource Management features (DRS & HA), and is currently working as a Technical Marketing Manager for VMware Cloud on AWS. Brian is a co-author of the PowerCLI Deep Dive 2nd edition book. He has helped develop VMware certification courses and exams and presents around the world at VMware User Conferences, AWS Summits, Interop, as well as other industry Conferences. Brian is also a Microsoft MVP.

6 thoughts on “Audit and Manage ESXi Hosts with PowerCLI

  1. Jonathan Stewart

    Brian,

    You might change the line:

    $Hardware = Get-VMhost | where {$_.ConnectionState –eq $true} | Get-VMHostHardware | Sort-Object BiosVersion –Unique

    to:

    $Hardware = Get-VMhost | where {$_.ConnectionState –eq “Connected”} | Get-VMHostHardware | Sort-Object BiosVersion –Unique

    Reply
  2. Chris Nakagaki

    FINALLY! I can dump a bunch of my crap liners.
    $NewObj.BIOs = (($TargetESXServerView.Runtime.HealthSystemRuntime.SystemHealthInfo.NumericSensorInfo | where {$_.Name -like “*BIOS*” -and $_.SensorType -eq “Software Components”}).Name) -replace(“.* BIOS “,””) -replace(” .*”,””)
    $NewObj.ServiceTag = ($TargetESXServerView.hardware.systeminfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “servicetag”}).identifierValue -replace(” “,””)
    $NewObj.AssetTag = ($TargetESXServerView.hardware.systeminfo.OtherIdentifyingInfo | where {$_.IdentifierType.Key -eq “assettag”}).identifierValue -replace(” “,””)

    Reply
  3. Chris Nakagaki

    Not sure the PCI device information is useful on it’s own, but would be nice to see driver/firmware related to those PCI devices. Not sure if that’s possible w/ vCenter API’s though.

    Reply
  4. Howard Simpson

    Hi Brian,

    You may be interested to know that our company has written a tool which automatically documents the configuration of your VMware environment.

    We’ve recently released an update which includes far more detail being pulled from VMware including ESX hosts.

    I hope it’s ok to post a link to it here:
    http://www.centrel-solutions.com/xiaconfiguration/capabilities.aspx?capability=audit-and-inventory-vmware-esx-host-configuration-and-create-documentation

    If you want to know more, please do get in touch with me.

    Howard Simpson

    Reply
  5. VJ

    Hi Brian,

    ‘get-vmhosthardware’ is reporting a different Serial Number than esxcli using $esxcli.hardware.platform.get().SerialNumber.

    I checked the hardware and vcenter. The serial number is the one that i got through esxcli. I could not find anywhere on the hardware, or in vcenter, the one that i got from ‘get-vmhosthardware’.

    Thanks,
    VJ

    Reply
  6. Evan Talley

    Getting the hardware info is crashing PowerShell ISE ever since we upgraded vCenter to 6.5 U1. What gives? I have upgraded PowerCLI to 6.5 R1, but that did not help. It seems to be only crashing when we run it against VM Hosts that are running 6.0 U3 or earlier. When we run it on 6.5 U1 hosts, PowerShell ISE does not crash.

    What is really strange is the command still returns the correct results. PowerShell ISE just crashes a second or two afterwards.

    C:\Scripts> Get-VMHost $NewVMHost | Get-VMHostHardware

    VMHost.Name Manufacturer Model SerialNumber AssetTag CpuModel CpuCoreCountTotal NicCount
    ———– ———— —– ———— ——– ——– —————– ——–
    10.96.120.21 Dell Inc. …ge T330 XXXXXXX unknown Intel(R) Xeon(R) … 4 3

    C:\Scripts>

    And then I get a pop-up that says PowerShell ISE has to close:

    Fault bucket 128037918602, type 5
    Event Name: PowerShell
    Response: Not available
    Cab Id: 0

    Problem signature:
    P1: powershell_ise.exe
    P2: 10.0.10586.117
    P3: System.InvalidCastException
    P4: System.InvalidCastException
    P5: unknown
    P6: ervice.VMHostHardwareRetrieval.GetCimPropertyValue
    P7: unknown
    P8:
    P9:
    P10:

    Reply

Leave a Reply

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

*