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

Basic HTML and HTML5: Make Dead Links Using the Hash Symbol

<h2>CatPhotoApp</h2><main> <p>Click here to view more <a href="http://freecatphotoapp.com" target="_blank">cat photos</a>.</p> <img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange…

Great GPL Windows Admin Tools

1. Wireshark 2. amanda.org (backup server) 3. mailarchiva.com (mail backup) 4. http://rbac.codeplex.com (remote admin for Exchange servers) 5. Core Configurator, ,…

PowerShell: Move Virtual Machine Storage Using VMM

# moveVmStorageUsingVmm.ps1 # Version 0.01 $vmNames=@( 'TESTVM0001', 'TESTVM0002', 'TESTVM0003' ) $storageLocations=@( 'C:\ClusterStorage\BLOB001', 'C:\ClusterStorage\BLOB002', 'C:\ClusterStorage\BLOB003' )…