Enabling LLDP on ESXi standard vSwitches

I developed this script based on a post by Shanon Olsson and thought it might be helpful for someone:

#!/bin/sh
 
switch=vSwitch0
 
# get the list of ports on the vSwitch
ports=$(vsish -e "ls" "net/portsets/$switch/ports")
 
for p in $ports; do
    # search for the UPLINK flag on the port
    c=$(vsish -e "get" "net/portsets/$switch/ports/${p}status" | grep 'flags:.*UPLINK')
    [ -n "$c" ] && uplinks="$uplinks $p"
done
 
for u in $uplinks; do
    # enable LLDP on all the uplink ports
    vsish -e "set" "net/portsets/$switch/ports/${u}lldp/enable" 1
done

#!/bin/sh switch=vSwitch0 # get the list of ports on the vSwitch ports=$(vsish -e "ls" "net/portsets/$switch/ports") for p in $ports; do # search for the UPLINK flag on the port c=$(vsish -e "get" "net/portsets/$switch/ports/${p}status" | grep 'flags:.*UPLINK') [ -n "$c" ] && uplinks="$uplinks $p" done for u in $uplinks; do # enable LLDP on all the uplink ports vsish -e "set" "net/portsets/$switch/ports/${u}lldp/enable" 1 done