VMware Cloud Community
narene
Contributor
Contributor
Jump to solution

Get list of ESXi Hosts, Versions, Builds, NIC FW/Driver Version by Cluster

Hello,

I'm trying to get an inventory of ESXi build, version and NIC card FW/Driver version by cluster. I like the output I get from a script I have to get the first part (ESXi build/version) by cluster, but I'm trying to add the additional NIC info columns.

The first (simple) script:

$Clusters = Get-Cluster

foreach ($Cluster in $Clusters)

{
Write-Host "##"$Cluster

$Cluster | Get-VMHost | Select @{Label = "Host"; Expression = {$_.Name}} ,
@{Label = "ESX Version"; Expression = {$_.version}},
@{Label = "ESX Build" ; Expression = {$_.build}} |
Sort-Object -Property Host | Format-Table -AutoSize -Wrap

}

That output looks like:

## cluster1

Host ESX Version ESX Build
---- ----------- ---------
host1 7.0.3 21313628
host2 7.0.3 21313628
host3 7.0.3 21313628

I also have one that kinda works to get the info I want, but because it processes each object I get headers for each object and not just 

one set of headers for the cluster as a whole like above:

$Clusters = Get-Cluster
  foreach ($Cluster in $Clusters)
  {
  Write-Host "##########"$Cluster"##########"
     ForEach-Object -Process {
      $Cluster | Get-VMHost -Server $_ -PipelineVariable esx |
        ForEach-Object -Process {
          $esxcli = Get-EsxCli -VMHost $esx -V2
          $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'VMHost'; E = { $esx.Name } },
              @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
              @{N = 'VMHost Version'; E = { $esx.Version } },
              @{N = 'VMHost Build'; E = { $esx.Build } },
              @{N='Driver';E={$_.DriverINfo.Driver}},
              @{N='FirmwareVersion';E={$_.DriverInfo.FirmwareVersion}},
              @{N='Driver Version';E={$_.DriverInfo.Version}} |
              Format-Table -AutoSize -Wrap
            }
        }
    }

But that produces output like this:

########## cluster1##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

With headers for each host in the cluster. (Cause that's what the script tells it to do w/ the for-each 😑)

Any tips on getting a listing more like the first script, breaking out the headers for the cluster as a whole, but w/ the additional NIC info columns?

I'm a relative PS newbie, so please forgive me if I'm overlooking something easy/trivial.

I've looked at something like: https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/PowerCLI-Script-to-get-ESXi-Network-St...

But I can't quite get it to work.

TIA for any guidance!

 

0 Kudos
2 Solutions

Accepted Solutions
narene
Contributor
Contributor
Jump to solution

Got it! Using an earlier one of your suggestions @LucD and just moving the 

Format-Table

Inside one level:

Get-Cluster -PipelineVariable cluster |
Foreach-Object -Process {
  Write-Host "##########"$Cluster"##########"
     ForEach-Object -Process {
      $Cluster | Get-VMHost -PipelineVariable esx |
        ForEach-Object -Process {
          $esxcli = Get-EsxCli -VMHost $esx -V2
          $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'VMHost'; E = { $esx.Name } },
              @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
              @{N = 'VMHost Version'; E = { $esx.Version } },
              @{N = 'VMHost Build'; E = { $esx.Build } },
              @{N='Driver';E={$_.DriverINfo.Driver}},
              @{N='FirmwareVersion';E={$_.DriverInfo.FirmwareVersion}},
              @{N='Driver Version';E={$_.DriverInfo.Version}}
            }
        }| Format-Table -AutoSize -Wrap
    }

Now it displays EXACTLY how I need it:

########## cluster 1##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0


########## cluster 2##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host3 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host4 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

########## cluster 3##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host5 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host6 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

 

View solution in original post

narene
Contributor
Contributor
Jump to solution

Added HW Bios version, and cleaned up some of the table header names:

 

Get-Cluster -PipelineVariable cluster |
Foreach-Object -Process {
  Write-Host "##########"$Cluster"##########"
     ForEach-Object -Process {
      $Cluster | Get-VMHost -PipelineVariable esx |
        ForEach-Object -Process {
          $esxcli = Get-EsxCli -VMHost $esx -V2
          $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'ESXi Host'; E = { $esx.Name } },
              @{N = 'BIOS Version'; E = { $esx.ExtensionData.Hardware.BiosInfo.BiosVersion } },
              @{N = 'Product'; E = { $esx.ExtensionData.Config.Product.Name } },
              @{N = 'ESXi Version'; E = { $esx.Version } },
              @{N = 'ESXi Build'; E = { $esx.Build } },
              @{N='NIC Driver';E={$_.DriverINfo.Driver}},
              @{N='NIC FW Version';E={$_.DriverInfo.FirmwareVersion}},
              @{N='NIC Driver Version';E={$_.DriverInfo.Version}}
            }
        }| Format-Table -AutoSize -Wrap
    }

 

 

 Thanks @LucD for all of your help and willingness to point me in the right direction. Greatly appreciated!

View solution in original post

13 Replies
LucD
Leadership
Leadership
Jump to solution

Move that Format-Table outside the loops and change that 1st foreach to a Foreach-Object.

 

 

Get-Cluster -PipelineVariable cluster |
Foreach-Object -Process {
  Write-Host "##########"$Cluster"##########"
  $Cluster | Get-VMHost -PipelineVariable esx |
  ForEach-Object -Process {
     $esxcli = Get-EsxCli -VMHost $esx -V2
     $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'VMHost'; E = { $esx.Name } },
        @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
        @{N = 'VMHost Version'; E = { $esx.Version } },
        @{N = 'VMHost Build'; E = { $esx.Build } },
        @{N='Driver';E={$_.DriverINfo.Driver}},
        @{N='FirmwareVersion';E={$_.DriverInfo.FirmwareVersion}},
        @{N='Driver Version';E={$_.DriverInfo.Version}}
  }
} |
Format-Table -AutoSize -Wrap

 

 

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

narene
Contributor
Contributor
Jump to solution

Thanks. That gives me this error:

 

########## cluster 1##########
Get-VMHost : Cannot bind parameter 'Server'. Cannot convert the "cluster 1" value of type
"VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl" to type "VMware.VimAutomation.ViCore.Types.V1.VIServer".
At C:\Scripts\GetClusterHosts\GetESXiHostFWBIOSbyCluster-2.ps1:5 char:37
+ $cluster | Get-VMHost -Server $_ -PipelineVariable esx |
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Get-VMHost], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

########## cluster 2##########
Get-VMHost : Cannot bind parameter 'Server'. Cannot convert the "cluster 2" value of type
"VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl" to type "VMware.VimAutomation.ViCore.Types.V1.VIServer".
At C:\Scripts\GetClusterHosts\GetESXiHostFWBIOSbyCluster-2.ps1:5 char:37
+ $cluster | Get-VMHost -Server $_ -PipelineVariable esx |
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Get-VMHost], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

 

Line 5 char 37 is the $_ in: 

$Cluster | Get-VMHost -Server $_ -PipelineVariable esx

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you connected to a vCenter?
That Server parameter should not be there.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

narene
Contributor
Contributor
Jump to solution

Bad copy/paste. Apologies.

I reconnected to vcenter. Re-ran and it's getting there. I get:

########## cluster1##########
########## cluster2##########
########## cluster3##########
VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host3 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host4 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

 

It's lumping a list of the datacenter objects followed by a list of all hosts in all clusters.

The columns are exactly what I need; thank you!

It'd just be nice to be able to break the hosts out by datacenter.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not sure what you mean.
Do you want to include a column with the name of the Datacenter?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
narene
Contributor
Contributor
Jump to solution

The columns are fine/exactly what I need. The hosts separated out by their respective datacenters.

 

Like a list of hosts in each datacenter w/ the current columns:

 

########## cluster 1##########
VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

########## cluster 2##########
VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

########## cluster 3##########
VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host3 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host4 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean like this?

Get-Datacenter -PipelineVariable dc |
    Get-Cluster -PipelineVariable cluster |
    ForEach-Object -Process {
        Write-Host "##########$($dc.Name)##########"
        Write-Host "##########$($Cluster.Name)##########"
        $Cluster | Get-VMHost -PipelineVariable esx |
            ForEach-Object -Process {
                $esxcli = Get-EsxCli -VMHost $esx -V2
                $esxcli.network.nic.get.invoke(@{nicname = "vmnic0" }) | select @{N = 'VMHost'; E = { $esx.Name } },
                @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
                @{N = 'VMHost Version'; E = { $esx.Version } },
                @{N = 'VMHost Build'; E = { $esx.Build } },
                @{N = 'Driver'; E = { $_.DriverINfo.Driver } },
                @{N = 'FirmwareVersion'; E = { $_.DriverInfo.FirmwareVersion } },
                @{N = 'Driver Version'; E = { $_.DriverInfo.Version } }
            }
        } |
        Format-Table -AutoSize -Wrap


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
narene
Contributor
Contributor
Jump to solution

Sorry. I meant cluster, but it's still just spitting out a cluster list followed by ALL hosts:

##########cluster 1##########
##########cluster 2##########
##########cluster 3##########
##########cluster 4##########
##########cluster 5##########
##########cluster 6##########
##########cluster 7##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host3 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host4 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host5 VMware ESXi 7.0.3 20842708 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host6 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host7 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host8 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host9 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, last attempt

 

Get-Cluster -PipelineVariable cluster |
    ForEach-Object -Process {
        Out-String -InputObject "##########$($Cluster.Name)##########" | Out-Default
        $Cluster | Get-VMHost -PipelineVariable esx |
            ForEach-Object -Process {
                $esxcli = Get-EsxCli -VMHost $esx -V2
                $esxcli.network.nic.get.invoke(@{nicname = "vmnic0" }) | select @{N = 'VMHost'; E = { $esx.Name } },
                @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
                @{N = 'VMHost Version'; E = { $esx.Version } },
                @{N = 'VMHost Build'; E = { $esx.Build } },
                @{N = 'Driver'; E = { $_.DriverINfo.Driver } },
                @{N = 'FirmwareVersion'; E = { $_.DriverInfo.FirmwareVersion } },
                @{N = 'Driver Version'; E = { $_.DriverInfo.Version } }
            }
        } |
        Format-Table -AutoSize -Wrap

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
narene
Contributor
Contributor
Jump to solution

That's it! Minus the column formatting , which seems to have gotten lost 😕. Not sure why since the `Out-Default` should let it get formatted by the `Format-Table` at the end. Thanks so much for your help @LucD!

 

##########cluster 1##########

VMHost : host 1
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 21313628
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0

VMHost : host2
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 21313628
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0


##########cluster 2##########

VMHost : host3
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 20842708
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0

VMHost : host4
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 21313628
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0


#########cluster 3##########

VMHost : host5
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 21313628
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0

VMHost : host6
VMHost Product : VMware ESXi
VMHost Version : 7.0.3
VMHost Build : 21313628
Driver : i40en
FirmwareVersion : 7.00 0x80004feb 1.2228.0
Driver Version : 2.2.4.0  

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Leave out the Out-Default on the Select-Object


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
narene
Contributor
Contributor
Jump to solution

Got it! Using an earlier one of your suggestions @LucD and just moving the 

Format-Table

Inside one level:

Get-Cluster -PipelineVariable cluster |
Foreach-Object -Process {
  Write-Host "##########"$Cluster"##########"
     ForEach-Object -Process {
      $Cluster | Get-VMHost -PipelineVariable esx |
        ForEach-Object -Process {
          $esxcli = Get-EsxCli -VMHost $esx -V2
          $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'VMHost'; E = { $esx.Name } },
              @{N = 'VMHost Product'; E = { $esx.ExtensionData.Config.Product.Name } },
              @{N = 'VMHost Version'; E = { $esx.Version } },
              @{N = 'VMHost Build'; E = { $esx.Build } },
              @{N='Driver';E={$_.DriverINfo.Driver}},
              @{N='FirmwareVersion';E={$_.DriverInfo.FirmwareVersion}},
              @{N='Driver Version';E={$_.DriverInfo.Version}}
            }
        }| Format-Table -AutoSize -Wrap
    }

Now it displays EXACTLY how I need it:

########## cluster 1##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host1 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host2 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0


########## cluster 2##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host3 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host4 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

########## cluster 3##########

VMHost VMHost Product VMHost Version VMHost Build Driver FirmwareVersion Driver Version
------ -------------- -------------- ------------ ------ --------------- --------------
host5 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0
host6 VMware ESXi 7.0.3 21313628 i40en 7.00 0x80004feb 1.2228.0 2.2.4.0

 

narene
Contributor
Contributor
Jump to solution

Added HW Bios version, and cleaned up some of the table header names:

 

Get-Cluster -PipelineVariable cluster |
Foreach-Object -Process {
  Write-Host "##########"$Cluster"##########"
     ForEach-Object -Process {
      $Cluster | Get-VMHost -PipelineVariable esx |
        ForEach-Object -Process {
          $esxcli = Get-EsxCli -VMHost $esx -V2
          $esxcli.network.nic.get.invoke(@{nicname="vmnic0"}) | select @{N = 'ESXi Host'; E = { $esx.Name } },
              @{N = 'BIOS Version'; E = { $esx.ExtensionData.Hardware.BiosInfo.BiosVersion } },
              @{N = 'Product'; E = { $esx.ExtensionData.Config.Product.Name } },
              @{N = 'ESXi Version'; E = { $esx.Version } },
              @{N = 'ESXi Build'; E = { $esx.Build } },
              @{N='NIC Driver';E={$_.DriverINfo.Driver}},
              @{N='NIC FW Version';E={$_.DriverInfo.FirmwareVersion}},
              @{N='NIC Driver Version';E={$_.DriverInfo.Version}}
            }
        }| Format-Table -AutoSize -Wrap
    }

 

 

 Thanks @LucD for all of your help and willingness to point me in the right direction. Greatly appreciated!