VMware Cloud Community
tdubb123
Expert
Expert

getting serial numbers on hosts

I am trying to get all my hostname, serial numbers but the cisco host serial is located

{$_.summary.hardware.otheridentifyinginfo[0].identifiervalue}


while the dell is located{$_.summary.hardware.otheridentifyinginfo[1].identifiervalue}


how do I modify the below command to show both?


get-vmhost | get-view | select NAme, @{N="Vendor"; e={$_.summary.hardware.vendor}}, @{N=

"tag"; e={$_.summary.hardware.otheridentifyinginfo[0].identifiervalue}}

0 Kudos
1 Reply
LucD
Leadership
Leadership

In the Expression part of a calculated property you can have a code block.

You can do all required testing and calculations in that block.

Something like this (you'll have to check the Vendor tests, I don't have all that different HW available for testing)

Get-VMHost | select Name,

    @{N="Vendor"; e={$_.ExtensionData.Summary.Hardware.Vendor}},

    @{N="Tag"; e={

        if($_.ExtensionData.Summary.Hardware.Vendor -match 'Cisco'){

            $_.ExtensionData.Summary.Hardware.OtherIdentifyinginfo[0].IdentifierValue

        }

        elseif($_.ExtensionData.Summary.Hardware.Vendor -match 'Dell'){

            $_.ExtensionData.Summary.Hardware.OtherIdentifyinginfo[1].IdentifierValue

        }}}


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

0 Kudos