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

Office 365 User Logon Instructions

How to Access Email via Outlook Web Access (OWA) Navigate to: https://login.microsoftonline.com/common/oauth2/authorize?client_id=00000002-0000-0ff1-ce00-000000000000&redirect_uri=https%3a%2f%2foutlook.office365.com%2fowa%2f&resource=00000002-0000-0ff1-ce00-000000000000&response_mode=form_post&response_type=code+id_token&scope=openid&msafed=1&msaredir=1&client-request-id=d6f712e4-8e0b-c690-dcc7-3082fcfa3760&protectedtoken=true&claims=%7b%22id_token%22%3a%7b%22xms_cc%22%3a%7b%22values%22%3a%5b%22CP1%22%5d%7d%7d%7d&nonce=638636475879321385.58dd735b-4862-46c7-8d7a-ae13e3f0226d&state=Dcs7FoAwCABBos_jYBIIH48TRVtLry_FbLcFANa0pNIyYMqurMPE7WDq7LKLRxjLicOVcOhl6GET59355qcRaZR8t_p-s_4 Input the provided…

PowerShell: Convert Between Various SSL Certificate Formats

# Install Choco (look for instructions in this blog)# Install openssl.lightchoco install openssl.light -y #…

PowerShell: Adding a New Domain Controller

Error when trying to run DCPROMO on a Windows 2019 Server: ---------------------------Active Directory Domain Services…