Use PowerShell to Discover Network Switch and port number

 If you are working with Networks, that I am, you can sometimes have trouble to find out what switch port a computer is connected to. That can be because of bad marking of a network socket or because a cable simply just disappear into a wall and you are not able to follow it all the way to the rack cabinet.

Let me show you an easy way to discover not just port number, but also name of the switch and VLAN for the connection. You will have to run the script below as an administrator, in order for it to work.

Script:

# Is Module installed - install if not available.
if (Get-Module -ListAvailable -Name PSDiscoveryProtocol) {
  Import-Module PSDiscoveryProtocol
}
else {
  Install-Module -Name PSDiscoveryProtocol -Force
  Import-Module PSDiscoveryProtocol
}
$Packet = Invoke-DiscoveryProtocolCapture -Type LLDP
Get-DiscoveryProtocolData -Packet $Packet

Be aware that you will need to have a manage lager 3 switch,  for the LLDP protocol,
 to collect these information.









As you can see above the PC that run this script is in port 1 on VLAN 10 and the switch is the model WS-C2960-48TT-L. That will be a 48-ports Cisco Catalyst switch.

Comments

Popular posts from this blog

How to get Public IP Using PowerShell

Use ChatGPT to write PowerShell Scripts