Need to find your switch port? Maybe you’re experiencing network connectivity issues (not ideal) or perhaps you have a compromised device generating too much traffic to your network (not great either). Maybe you just want to know that you’re connected to the right VLAN (we’ve got our fingers crossed).
Way back when your grandparents were walking an hour to school in the snow, troubleshooting networking issues meant tracing the physical cables from device to port. We’re all about you getting your steps in, but with this easy-to-use script, you can save your workouts for the gym!
This script will show you which switch port your network cables are connected to without having to move an inch. First, the PSDiscoveryProtocol module intercepts the network packets (small segments of data sent over a network connection) on local or remote computers. The script then extracts the following information stored in the packets: model number, description, VLAN, port, device, IP Address, computer, and packet type.
Once you have this data, it’s time to start troubleshooting. If the port itself is corrupted, you can physically change the port your device is connected to. If you’re connected to an unexpected VLAN, change the settings of the switch via the associated web user interface.
The Script:
Atera does not guarantee the integrity, availability, security, virus-free, safety, lawfulness, non-infringement, rights’ status, or functionality of the scripts. The use of the shared scripts is at your own risk. Scripts are provided “AS IS”. *
###
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name PSDiscoveryProtocol
$Packet = Invoke-DiscoveryProtocolCapture -Type LLDP
Get-DiscoveryProtocolData -Packet $Packet
###
Technical Notes:
- Admin permissions needed to run this script as it installs a PowerShell module.
- The network packets used in this script are the CDP (Cisco Discovery Protocol) and LLDP (Link Layer Discovery Protocol packets).
- This script can capture packets simultaneously on multiple computers using the new -Parallel parameter on ForEach-Object. Note that this requires PowerShell version 7. To gather switch port details for multiple computers simultaneously, replace lines 3 and 4 in the script with the following:
COMPUTER1′, ‘COMPUTER2’, ‘COMPUTER3’ | ForEach-Object -Parallel { Invoke-DiscoveryProtocolCapture -ComputerName $_ | Get-DiscoveryProtocolData
} - The PSDiscoveryProtocol command does not return all information available in CDP and LLDP packets. To extract and use all the information available in the packets, you can use the command, Export-Pcap, and open the pcap file in Wireshark or a similar tool. To do this, replace line 4 with Export-Pcap -Path packets.pcap