Hello,
I've been trying some of the existing scripts found here to gather network switch port CDP information from pNICs on ESXi hosts. These scripts assume only one host is queried or they connect to a vCenter Server to gather a VMHost list. When I try connecting to multiple ESXi hosts I run into this error:
Method invocation failed because [System.Object[]] doesn't contain a method named 'QueryNetworkHint'.
Can a PowerCLI script perform the following task?
I would like the script to start by connecting to multiple ESXi hosts that are not managed in vCenter. The Get-PowerCLIConfiguration Default Server Mode is set to Multiple so that 'Get-VMHost' returns list of VMHosts.
The script would then gather information from each pNIC on each host and export the results to HTML table format as shown in the attached .htm example. I'm hoping for help with the section that gathers the information for multiple ESXi hosts.
# Begin script
Connect-VIServer esx1 -user user1 -password password1
Connect-VIServer esx2 -user user1 -password password1
Connect-VIServer esx3 -user user1 -password password1
$filename = "C:\www\cdp_example.htm"
???
# Example data
$report = @()
$row = "" | select VMHost, vSwitch, physNIC, DevID, PortID, VLANID, Speed, MAC
$row.VMHost = "esx1.example.com"
$row.vSwitch = "vSwitch0"
$row.physNIC = "vmnic0"
$row.DevID = "switch1.example.com"
$row.PortID = "GigabitEthernet3/5"
$row.VLANID = "101"
$row.Speed = "1000"
$row.MAC = "00:0c:a3:4b:ff:01"
$report += $row
$report | ConvertTo-Html -title "ESXi CDP Info" | Out-File $filename
--
Example HTML table output.
<html>
<head><style>body { background-color:#EEEEEE; }
body,table,td,th { font-family:Tahoma; color:Black; Font-Size:10pt }
th { font-weight:bold; background-color:#CCCCCC; }
td { background-color:white; }</style></head>
<body>
<table>
<tr><th>VMHost</th><th>vSwitch</th><th>physNIC</th><th>DevID</th><th>PortID</th><th>VLANID</th><th>Speed</th><th>Duplex</th><th>MAC</th></tr>
<tr><td>esx1.example.com</td><td>vSwitch0</td><td>vmnic0</td><td>switch1.example.com</td><td>GigabitEthernet2/4</td><td>101</td><td>1000</td><td>Full</td><td>00:0c:a3:4b:ff:01</td></tr>
<tr><td>esx1.example.com</td><td>vSwitch0</td><td>vmnic1</td><td>switch2.example.com</td><td>GigabitEthernet3/5</td><td>101</td><td>1000</td><td>Full</td><td>00:0c:a3:4b:ff:02</td></tr>
<tr><td>esx2.example.com</td><td>vSwitch0</td><td>vmnic0</td><td>switch1.example.com</td><td>GigabitEthernet3/5</td><td>101</td><td>1000</td><td>Full</td><td>00:0c:a3:4b:ff:03</td></tr>
<tr><td>esx2.example.com</td><td>vSwitch0</td><td>vmnic1</td><td>switch2.example.com</td><td>GigabitEthernet3/5</td><td>101</td><td>1000</td><td>Full</td><td>00:0c:a3:4b:ff:04</td></tr>
</table>
</body></html>
--
Thanks!