Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active November 12, 2019 16:22
Show Gist options
  • Select an option

  • Save altrive/6044589 to your computer and use it in GitHub Desktop.

Select an option

Save altrive/6044589 to your computer and use it in GitHub Desktop.
PowerShell v4 new cmdlet "Test-NetConnection"
#if ComputerName is not supplied. Connect to "internetbeacon.msedge.net" by default
Test-NetConnection
#Test ping(ICMP protocol)
Test-NetConnection "google.com"
#Ping with TraceRoute
Test-NetConnection "google.com" -TraceRoute
#Set Remote ComputerName
$target = "172.16.100.6"
#Specift Port by Protocol(HTTP/SMB/RDP/WINRM)
Write-Host -NoNewLine ("{0,-5} Port({1,4}): " -f "HTTP","80")
Test-NetConnection -ComputerName $target -CommonTCPPort HTTP -InformationLevel Quiet
Write-Host -NoNewLine ("{0,-5} Port({1,4}): " -f "SMB","445")
Test-NetConnection -ComputerName $target -CommonTCPPort SMB -InformationLevel Quiet
Write-Host -NoNewLine ("{0,-5} Port({1,4}): " -f "RDP","3389")
Test-NetConnection -ComputerName $target -CommonTCPPort RDP -InformationLevel Quiet
Write-Host -NoNewLine ("{0,-5} Port({1,4}): " -f "WINRM","5985")
Test-NetConnection -ComputerName $target -CommonTCPPort WINRM -InformationLevel Quiet
#Specific Port by Number
Write-Host -NoNewLine ("{0,-5} Port({1,4}): " -f "Unknown","139")
Test-NetConnection -ComputerName $target -Port 139 -InformationLevel Quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment