I am trying to run a script to display certain info but cannot get the host service tag to display. I am getting all other info EXCEPT for service tag. Please see the below for what I have so far. Any help would be appreciated.
#make an entry in the array for each one
foreach ($line in $list){
$row = "" | select id, vmname , dnsname, model, manufacturer, servicetag, ipaddr, vmhostid, vmguestos, ostype, vmvcpu, vmpowerstate,vmgueststate, vmhostname, vmhostcpu, vmhostcore, vmhostthread, version, build, vc, dc, cluster, date
$row.id = $line.id
$row.vmname = $line.name
$row.dnsname = $line.guest.hostname
$row.model = $line.vmhost.model
$row.manufacturer = $line.VMhost.Manufacturer
$row.servicetag = $line.vmhost.ServiceTag
$row.ipaddr = $line.guest.ipaddress[0]
$row.vmhostid = $line.vmhostid
$row.vmhostname = $line.vmhost
$row.vmguestos = $line.guest.osfullname
Try with this line
$row.servicetag = ($line.VMHost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | where{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What do you have in $list?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$list = Get-VM -Server $vc -Location $cluster | sort
Try with this line
$row.servicetag = ($line.VMHost.ExtensionData.Hardware.SystemInfo.OtherIdentifyingInfo | where{$_.IdentifierType.Key -like "ServiceTag"}).IdentifierValue
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Works like magic. Thank you so much
Thanks LucD! I've modified this for a one-liner for a quick command line run:
Get-View -ViewType HostSystem | Select Name, @{n="ServiceTag"; e={($_.Hardware.SystemInfo.OtherIdentifyingInfo | ?{$_.IdentifierType.Key -eq "ServiceTag"}).IdentifierValue}} | sort name