Posted On January 30, 2023

PowerShell: Quickly Test Connectivity from a List of Sources toward a Destination on a Specific Port

kimconnect 0 comments
blog.KimConnect.com >> Codes , Networking , Windows >> PowerShell: Quickly Test Connectivity from a List of Sources toward a Destination on a Specific Port
# testRemotePort.ps1

$connectFrom=@'
windows1
windows2
'@
$connectTo=@'
\\servername\sharename
'@
$testPort=445

$sources=@($connectFrom -split "`n")|%{$_.Trim()}
$destinations=@($connectTo -split "`n")|%{$_.Trim()}
$results=@()
foreach($source in $sources){
    foreach($destination in $destinations){
        $result=invoke-command -computername $source {
            param($destination,$testPort)
            write-host "$env:computername to $destination`:$testPort => " -nonewline
            $result=try{if(test-netconnection $destination -port $testPort -informationLevel Quiet){'Open'}else{'Closed'}}catch{write-warning $_;'Unknown'}
            write-host "$result"
            return $result
        } -Args $destination,$testPort
        $results+=[pscustomobject]@{
            source=$source
            destination=$destination
            port=$testPort
            status=$result
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Install PBX in a Flash

Download and install FreePBX version 13Set static IPsifconfig <= to find interface namevim /etc/sysconfig/network-scripts/ifcfg-eth0---------ADD-----------BOOTPROTO="static"IPADDR=192.168.139.139NETMASK=255.255.255.0BROADCAST=192.168.139.255NM_CONTROLLED=noONBOOT="yes"-----------------------vim /etc/sysconfig/network-scripts/ifcfg-eth1---------ADD-----------BOOTPROTO="dhcp"ONBOOT="yes"-----------------------vim…

Active Directory Domain Controller Certificates Installation Guide

Overview This article deals with Domain Controllers, rather than member servers. Thus, Active Directory or…

SQL Failover (Simple Method)

$servers="SQL01","SQL02","SQL03"; # Dynamic Credential method 1 $who = whoami if ($who.substring($who.length-2, 2) -eq "-admin"){$username=$who;} else…
Other project: DragonCoin.com