Automation

 View Only
Expand all | Collapse all

Get-VMHostHardware |

  • 1.  Get-VMHostHardware |

    Posted Mar 11, 2023 08:51 PM
    Hello,
     
    I'm using this command to collect HardwareInfo from ESXi
     
    $1 = $VMHost | Get-VMHostHardware -SkipAllSslCertificateChecks -ErrorAction SilentlyContinue
     
    Unfortunately, I got an error message :

    Cmdlet Get-VMHostHardware is not supported on PowerShell Core.
     
    Would you please assist me in solving the issue?


  • 2.  RE: Get-VMHostHardware |

    Posted Mar 11, 2023 09:17 PM

    What is there to solve?
    The message is rather clear, the cmdlet is not supported on PS Core.

    As alternatives, you could use PSv5.1 or get the HW info from the HostSystem object directly.
    What HW info specifically are you looking for?



  • 3.  RE: Get-VMHostHardware |

    Posted Mar 11, 2023 09:27 PM

    Ok, then it's more clear now, my Bad as I started creating the below loop in order to collect some details from ESXi

     

    Foreach ($VMHost in $ListOfVMHosts) {
        $1 = $null
        $1 = $VMHost | Get-VMHostHardware -SkipAllSslCertificateChecks -ErrorAction SilentlyContinue
        If ($1) {
            Write-Output -Message "Processing host $VMHost.Name [$Counter/$Count]"
            #Write-Host "Processing host $VMHost.Name [$Counter/$Count]"
     
            $HostHardware = $VMHost |  Get-VMHostHardware -SkipAllSslCertificateChecks
            $HostNetwork = $VMHost |  Get-VMHostNetwork
     
            $HostNetworkvMotionAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.VMotionEnabled -eq $true }
            $HostNetworkManagementTrafficAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.ManagementTrafficEnabled -eq $true }
            $HostNetworkvSANTrafficAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.VsanTrafficEnabled -eq $true }
     
            $MemoryTotalGB = [math]::Round($VMHost.MemoryTotalGB)
     
            $Object = [PSCustomObject]@{
                SerialNumber     = $HostHardware.SerialNumber # Serialnumber needs to be first for VLOOKUP to work in Excel
                vCenter          = $VMHost.Uid.Substring($VMHost.Uid.IndexOf('@') + 1).Split(":")[0]
                DataCenter       = ($VMHost | Get-Datacenter)
                Cluster          = $VMHost.Parent
                HostName         = $VMHost.Name
                Manufacturer     = $VMHost.Manufacturer
                Model            = $VMHost.Model
                Bios             = $HostHardware.BiosVersion
                Processor        = $VMHost.ProcessorType
                CPU              = $HostHardware.CpuCount
                CPUCores         = $HostHardware.CpuCoreCountTotal
                MemoryGB         = $MemoryTotalGB
                ESXVersion       = $VMHost.ExtensionData.Summary.Config.Product.FullName
                ESXLicenseKey    = $VMHost.LicenseKey
                DNS1             = $HostNetwork.DnsAddress[0]
                DNS2             = $HostNetwork.DnsAddress[1]
                Gateway          = $HostNetwork.VMKernelGateway
                ManagementDevice = $HostNetworkManagementTrafficAdapter.name
                ManagementIP     = $HostNetworkManagementTrafficAdapter.ip
                ManagementMTU    = $HostNetworkManagementTrafficAdapter.mtu
                vMotionDevice    = $HostNetworkvMotionAdapter.name
                vMotionIP        = $HostNetworkvMotionAdapter.ip
                vMotionMTU       = $HostNetworkvMotionAdapter.mtu
                vSANDevice       = $HostNetworkvSANTrafficAdapter.name
                vSANIP           = $HostNetworkvSANTrafficAdapter.ip
                vSANMTU          = $HostNetworkvSANTrafficAdapter.mtu
            }
     
            $Report.add($Object) | Out-Null
        } Else {
            Write-Output -Message  "There was an error processing host $VMHost.Name [$Counter/$Count]"
        }
        $Counter++
    }


  • 4.  RE: Get-VMHostHardware |
    Best Answer

    Posted Mar 11, 2023 10:35 PM

    You can do

    Foreach ($VMHost in $ListOfVMHosts) {
      Write-Output -Message "Processing host $VMHost.Name [$Counter/$Count]"
    
      $HostNetwork = $VMHost |  Get-VMHostNetwork
    
      $HostNetworkvMotionAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.VMotionEnabled -eq $true }
      $HostNetworkManagementTrafficAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.ManagementTrafficEnabled -eq $true }
      $HostNetworkvSANTrafficAdapter = $VMHost |  Get-VMHostNetworkAdapter -VMKernel |  Where-Object { $_.VsanTrafficEnabled -eq $true }
    
      $MemoryTotalGB = [math]::Round($VMHost.MemoryTotalGB)
    
      $Object = [PSCustomObject]@{
        SerialNumber = $VMHost.ExtensionData.Hardware.SystemInfo.SerialNumber
        vCenter = $VMHost.Uid.Substring($VMHost.Uid.IndexOf('@') + 1).Split(":")[0]
        DataCenter = ($VMHost | Get-Datacenter)
        Cluster = $VMHost.Parent
        HostName = $VMHost.Name
        Manufacturer = $VMHost.Manufacturer
        Model = $VMHost.Model
        Bios = $VMHost.ExtensionData.Hardware.BiosInfo.BiosVersion
        Processor = $VMHost.ProcessorType
        CPU = $VMHost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
        CPUCores = $VMHost.ExtensionData.Hardware.CpuInfo.NumCpuCores
        MemoryGB = $MemoryTotalGB
        ESXVersion = $VMHost.ExtensionData.Summary.Config.Product.FullName
        ESXLicenseKey = $VMHost.LicenseKey
        DNS1 = $HostNetwork.DnsAddress[0]
        DNS2 = $HostNetwork.DnsAddress[1]
        Gateway = $HostNetwork.VMKernelGateway
        ManagementDevice = $HostNetworkManagementTrafficAdapter.name
        ManagementIP = $HostNetworkManagementTrafficAdapter.ip
        ManagementMTU = $HostNetworkManagementTrafficAdapter.mtu
        vMotionDevice = $HostNetworkvMotionAdapter.name
        vMotionIP = $HostNetworkvMotionAdapter.ip
        vMotionMTU = $HostNetworkvMotionAdapter.mtu
        vSANDevice = $HostNetworkvSANTrafficAdapter.name
        vSANIP = $HostNetworkvSANTrafficAdapter.ip
        vSANMTU = $HostNetworkvSANTrafficAdapter.mtu
      }
    
      $Report.add($Object) | Out-Null
      $Counter++
    }
    


  • 5.  RE: Get-VMHostHardware |

    Posted Mar 13, 2023 07:48 PM

    Hi  

     

    Thank you it's working except that the Serial numbers aren't retrieved  

    I will do some other tests and keep you posted

     

    Thank you again



  • 6.  RE: Get-VMHostHardware |