<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hardware Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/hardware/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/hardware/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 10:24:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.10</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>hardware Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/hardware/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>Name that hardware</title>
		<link>https://www.lucd.info/2010/03/07/name-that-hardware/</link>
					<comments>https://www.lucd.info/2010/03/07/name-that-hardware/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sun, 07 Mar 2010 02:13:29 +0000</pubDate>
				<category><![CDATA[hardware]]></category>
		<category><![CDATA[PCI]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=1899</guid>

					<description><![CDATA[This post was triggered by the thread Retrieving ESX host hardware information in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This post was triggered by the thread <a href="https://communities.vmware.com/thread/258299?tstart=0" target="_blank" rel="noopener noreferrer">Retrieving ESX host hardware information</a> in the <a href="https://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli?view=discussions" target="_blank" rel="noopener noreferrer">PowerCLI</a> community. In that thread at a certain point the NIC HW</p>
<p style="text-align: center;">
<p>information was missing. The solution was to use the <strong>classId</strong>, which is <strong>0x0200</strong> for NICs, as a filter on the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.PciDevice.html" target="_blank" rel="noopener noreferrer">HostPciDevice</a> objects that are present under the <strong>pciDevice</strong> property in the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.HardwareInfo.html" target="_blank" rel="noopener noreferrer">HostHardwareInfo</a> object.</p>
<p>That made me think that this would be an ideal way to list all the hardware present on a server. But to my surprise a lot of the entries are listed as &#8220;unknown&#8221;. Since the <strong>vendorId</strong> and the <strong>deviceId</strong> are known I knew that this could be improved.</p>
<p style="text-align: center;"><a href="https://lucd.info/wp-content/uploads/2010/03/Script-O-Mania-22.png"><img decoding="async" class="shutter aligncenter" title="Script-O-Mania-2" src="https://lucd.info/wp-content/uploads/2010/03/Script-O-Mania-22-300x150.png" alt="" width="240" height="120" /></a></p>
<p><span id="more-1899"></span>When I used the following simple script on an <strong>IBM System x3650 M2 -[7947W3C]</strong></p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esx = Get-VMHost esx41.test.local | Get-View
Write-Host &quot;Slot`t`tClassId`tVendor`tDevice&quot;
$esx.Hardware.PciDevice | %{
	Write-Host $_.Id &quot;`t&quot; $_.VendorName &quot;`t&quot; $_.DeviceName
}</pre><p></p>
<p>a lot of the entries were marked <span style="background-color: #ffff00;">unknown</span>.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/HW-classic3.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-1915" title="HW-classic" src="https://lucd.info/wp-content/uploads/2010/03/HW-classic3.png" alt="" width="589" height="732" srcset="https://www.lucd.info/wp-content/uploads/2010/03/HW-classic3.png 736w, https://www.lucd.info/wp-content/uploads/2010/03/HW-classic3-241x300.png 241w" sizes="(max-width: 589px) 100vw, 589px" /></a></p>
<p>My first thought was to use the well-known PCIDatabase.com site to find the missing HW information.</p>
<p>But to my surprise when I used their CSV  vendor/device list to resolve the vendor- and deviceIds, I got exactly the <strong>same result</strong>. So now at least we know which list VMware uses to find the information about the HW <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Luckily there is another list available on the The <a href="https://pci-ids.ucw.cz/" target="_blank" rel="noopener noreferrer">PCI ID Repository</a> website. And bingo, with that list it was possible to retrieve all the HW information.</p>
<h2>The script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$esxName = &quot;esx41.test.local&quot;
$urlPCI = &quot;https://pci-ids.ucw.cz/v2.2/pci.ids&quot;
$filename = &quot;PCI.ids&quot;
$deviceTab = @{}
$forceDownload = $true

# Download file if not present or if forced download
if(!(Test-Path $filename) -or $forceDownload){
	$web = New-Object net.WebClient
	$web.downloadfile($urlPCI,$filename)
}

# Read file into hash tab
Get-Content $filename | where {$_.Length -ne 0 -and $_[0] -ne &quot;#&quot;} | %{
	if($_[0] -eq &quot;`t&quot;){
		if($_[1] -eq &quot;`t&quot;){
			$subdeviceId = $_.Substring(2,4)
			if(!$deviceTab[$vendorId].deviceTab.ContainsKey($subdeviceId)){
				$deviceTab[$vendorId].deviceTab[$subdeviceId] = $_.Substring(6).TrimStart(&quot; &quot;)
			}
		}
		else{
			$deviceId = &quot;0x&quot; + $_.Substring(1,4)
			if(!$deviceTab[$vendorId].deviceTab.ContainsKey($deviceId)){
				$deviceTab[$vendorId].deviceTab[$deviceId] = $_.Substring(5).TrimStart(&quot; &quot;)
			}
		}
	}
	else{
		$vendorId = &quot;0x&quot; + $_.Substring(0,4)
		if(!$deviceTab.ContainsKey($vendorId)){
			$deviceTab[$vendorId] = New-Object PSObject -Property @{
				Vendor = $_.Substring(4).TrimStart(&quot; &quot;)
				deviceTab = @{}
			}
		}
	}
}

# List all PCI devices and look up Vendor and description
$esx = Get-VmHost $esxName | Get-View
$esx.Hardware.PciDevice | %{
	$strVendorId = &quot;0x&quot; + &quot;{0}&quot; -f [Convert]::ToString($_.VendorId,16).ToUpper().PadLeft(4, '0')
	$strDeviceId = &quot;0x&quot; + &quot;{0}&quot; -f [Convert]::ToString($_.DeviceId,16).ToUpper().PadLeft(4, '0')
	New-Object PSObject -Property @{
		Slot = $_.Id
		Vendor = &amp;{if($deviceTab.ContainsKey($strVendorId)){$deviceTab[$strVendorId].Vendor}else{$strVendorId}}
		Device = &amp;{if($deviceTab[$strVendorId].deviceTab.ContainsKey($strDeviceId)){$deviceTab[$strVendorId].deviceTab[$strDeviceId]}else{$strDeviceId}}
	}
} | Sort-Object -Property Slot | ft</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 1</strong>: Name of the ESX/ESXi server for which you want to report the HW</p>
<p><strong>Line 2</strong>: The URL of the pci.ids file on the <a href="https://pci-ids.ucw.cz/" target="_blank" rel="noopener noreferrer">PCI ID Repository</a> website</p>
<p><strong>Line 3</strong>: The filename of file.</p>
<p><strong>Line 4</strong>: The vendor- and deviceId information will be stored in this <strong>hash table</strong>.</p>
<p><strong>Line 5</strong>: With this <strong>Boolean variable</strong> you can indicate if you want to download a fresh copy of the <strong>pci.ids</strong> file from the <a href="https://pci-ids.ucw.cz/" target="_blank" rel="noopener noreferrer">PCI ID Repository</a> website or if you want to use the file that is in the directory from where you run this script.</p>
<p><strong>Line 8-11</strong>: Simple use of the <a href="https://msdn.microsoft.com/en-us/library/system.net.webclient.aspx" target="_blank" rel="noopener noreferrer">net.WebClient</a> to download the <strong>pci.ids</strong> file. Note that if you are running the script behind a proxy you will have extend this logic to pass the proxy account and password.</p>
<p><strong>Line 14-38</strong>: This part of the script reads in the <strong>pci.ids</strong> file and stores it in hash table. The hash table makes it easier to lookup the vendor- and deviceId when we run through the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.PciDevice.html" target="_blank" rel="noopener noreferrer">HostPciDevice</a> objects.</p>
<p><strong>Line 14</strong>: The script skips the comments and the blank lines</p>
<p><strong>Line 15</strong>: As is noted in the comments in the pci.ids file, the entries in the file follow a convention. Lines starting with a TAB contain deviceId entries</p>
<p><strong>Line 16</strong>: Lines starting with two TABs contain subdevice entries. Note that this script does not distinguish between deviceIds and subdeviceIds.</p>
<p><strong>Line 29</strong>: No TABs means that the line contains a vendorId.</p>
<p><strong>Line 41-50</strong>: Now the script runs through all the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.PciDevice.html" target="_blank" rel="noopener noreferrer">HostPciDevice</a> objects and retrieves the vendor and device information from the hash table by using the vendorId and deviceId as keys into the hash table.</p>
<h2>The result</h2>
<p>As can be seen from the following screenshot we now get a complete overview of all the PCI HW that is present.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/03/HW-pci-ids1.png"><img decoding="async" class="alignnone size-full wp-image-1916" title="HW-pci-ids" src="https://lucd.info/wp-content/uploads/2010/03/HW-pci-ids1.png" alt="" width="760" height="745" srcset="https://www.lucd.info/wp-content/uploads/2010/03/HW-pci-ids1.png 950w, https://www.lucd.info/wp-content/uploads/2010/03/HW-pci-ids1-300x294.png 300w" sizes="(max-width: 760px) 100vw, 760px" /></a></p>
<p>No more need to run dedicated agents in the COS to gather this kind of report.</p>
<p>And thus also ideal for the ESXi servers !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2010/03/07/name-that-hardware/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
