Samer Sultan
https://www.sultansolutions.com
@SultanSolutions
Test-NetConnection [FQDN/IP Address] -Port [Port]Example:
Test-NetConnection google.com -Port 443Show only whether the TCP connection succeeded:
Test-NetConnection google.com -Port 443 |
Select-Object ComputerName, RemoteAddress, RemotePort, TcpTestSucceededTest-Connection [Hostname/IP]Example:
Test-Connection google.comSingle ping:
Test-Connection google.com -Count 1Resolve-DnsName [Hostname]Example:
Resolve-DnsName google.comQuery a specific DNS server:
Resolve-DnsName google.com -Server 8.8.8.8Get-NetIPConfigurationMore detailed information:
Get-NetIPConfiguration -DetailedTraditional output:
ipconfig /allGet-DnsClientServerAddressIPv4 only:
Get-DnsClientServerAddress -AddressFamily IPv4Clear-DnsClientCacheEquivalent command:
ipconfig /flushdnsGet-NetAdapterOnly connected adapters:
Get-NetAdapter |
Where-Object Status -eq "Up"Restart-NetAdapter -Name "Ethernet"For Wi-Fi:
Restart-NetAdapter -Name "Wi-Fi"Get-NetRouteIPv4 routes only:
Get-NetRoute -AddressFamily IPv4Default route:
Get-NetRoute -DestinationPrefix "0.0.0.0/0"Get-NetTCPConnectionEstablished connections only:
Get-NetTCPConnection -State EstablishedFind connections using a specific port:
Get-NetTCPConnection -LocalPort 443Get-NetTCPConnection -LocalPort [Port] |
Select-Object LocalAddress, LocalPort, State, OwningProcessThen find the process:
Get-Process -Id [PID]Example:
Get-Process -Id (Get-NetTCPConnection -LocalPort 443).OwningProcessTest-NetConnection google.com -TraceRouteTraditional command:
tracert google.comGet-NetNeighborIPv4 only:
Get-NetNeighbor -AddressFamily IPv4Get-NetFirewallProfileShow whether each firewall profile is enabled:
Get-NetFirewallProfile |
Select-Object Name, EnabledGet-NetFirewallRule |
Where-Object DisplayName -Like "*RDP*"Show enabled rules:
Get-NetFirewallRule |
Where-Object Enabled -eq "True"Get-NetTCPConnection -State ListenSort by port:
Get-NetTCPConnection -State Listen |
Sort-Object LocalPort |
Select-Object LocalAddress, LocalPort, OwningProcesshostnamePowerShell-native method:
$env:COMPUTERNAMEwhoamiPowerShell:
[System.Security.Principal.WindowsIdentity]::GetCurrent().NameGet-CimInstance Win32_ComputerSystem |
Select-Object Name, Domain, PartOfDomainnltest /dsgetdc:$env:USERDNSDOMAINCheck the logon server:
$env:LOGONSERVERGet-NetConnectionProfileDisplays whether the connection is:
- DomainAuthenticated
- Private
- Public
Invoke-RestMethod https://api.ipify.orgGet-NetIPAddress -AddressFamily IPv4 |
Where-Object IPAddress -NotLike "169.254*" |
Select-Object InterfaceAlias, IPAddress, PrefixLength80,443,3389 | ForEach-Object {
Test-NetConnection server01 -Port $_ |
Select-Object ComputerName, RemotePort, TcpTestSucceeded
}Test-Connection google.com -ContinuousStop with:
Ctrl + C