I wanted to automate a bit the query of LLDP on esxi vswitch. There are some nice posts on internet about that like https://www.provirtualzone.com/enable-lldp-in-vswitch/ for example. It explains in nice details about how this works. So lets automate this a little bit using powershell.
1 2 3 4 |
install-module posh-ssh $esxissh = New-SSHSession -ComputerName 'host3.greg.labs' -Credential (Get-Credential) $data = Invoke-SSHCommand -Command 'vsish -e cat /net/portsets/vSwitch3/ports/2348810379/lldp/rcache' -SSHSession $esxissh ($data.Output -join '#').split('-')|?{$_} |select @{n='type';e={$_.split('#')[1].split(' ')[1]}},@{n='dataLen';e={$_.split('#')[2].split(' ')[1]}}, @{n='data';e={$_.split(':')[3].replace('#','')}} | select type,dataLen,data,@{n='text';e={[System.Text.Encoding]::ASCII.GetString($_.data -split '(?=0x)' -ne '')} } |?{$_.type -notmatch '[137]' } | select type,text |
And we get in return nice object with lldp info.
2 0/13
4 host3 vmnic0
5 UBNT EdgeSwitch
6 EdgeSwitch 48 Lite, 1.9.2, Linux 3.6.5-03329b4a, 1.1.0.5102011
So the type 2 would represent switch interface, 5,6, the remote system (in my case this is edgeswitch). Its way easier to read than this 😉