{"id":372,"date":"2017-01-05T04:34:46","date_gmt":"2017-01-05T04:34:46","guid":{"rendered":"http:\/\/www.balajibandi.com\/?p=372"},"modified":"2017-04-28T05:53:30","modified_gmt":"2017-04-28T04:53:30","slug":"windows-powershell-common-networking-commands","status":"publish","type":"post","link":"https:\/\/www.balajibandi.com\/?p=372","title":{"rendered":"Windows PowerShell common networking commands"},"content":{"rendered":"<h1 class=\"entry-title\"><span style=\"text-decoration: underline;\"><strong><span style=\"color: #0000ff; text-decoration: underline;\">Windows PowerShell \u00a0common networking commands (IPCONFIG, PING, TRACERT, ROUTE NSLOOKUP,NETSTAT)<\/span><\/strong><\/span><\/h1>\n<p>Network Engineer to trouble shoot some of Windows Servers issue apart from Networking Devices. Maybe you need to check the IP address of a machine or test if its networking connection is working. Maybe you need to see if DNS is properly configured or check the latency between two hosts.<\/p>\n<p>If you have been in this field long enough, you probably have a few favorite commands that you learned years ago and use on a regular basis, like IPCONFIG or PING.<\/p>\n<p>There are literally hundreds of networking-related PowerShell cmdlets in Windows these days. Just try out this command on your machine:<\/p>\n<p><strong>Get-Command -Module Net* | Group Module \u00a0 &#8211; Give you all the list available in your Windows Servers or Windows 10<\/strong><\/p>\n<p id=\"MldbqBG\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-378 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902b9c458d43.png\" alt=\"\" width=\"732\" height=\"140\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902b9c458d43.png 1204w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902b9c458d43-300x57.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902b9c458d43-768x147.png 768w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902b9c458d43-1024x196.png 1024w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>But more important than knowing every one of them, is to know the most useful cmdlets that have the potential to replace those old commands that you can\u2019t live without.<\/p>\n<p>Only PowerShell can do that you\u2019ll find amazing new troubleshooting abilities\u2026<\/p>\n<h3>IPCONFIG<\/h3>\n<p>Description: This command has many options, but the most common usage is just to show the IP address, subnet mask and default gateway for each network adapter in a machine.<\/p>\n<p>PowerShell: Get-NetIPConfiguration or Get-NetIPAddress<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Get-NetIPConfiguration<\/li>\n<li>Get-NetIPAddress | Sort InterfaceIndex | FT InterfaceIndex, InterfaceAlias, AddressFamily, IPAddress, PrefixLength -Autosize<\/li>\n<li>Get-NetIPAddress | ? AddressFamily -eq IPv4 | FT \u2013AutoSize<\/li>\n<li>Get-NetAdapter Wi-Fi | Get-NetIPAddress | FT -AutoSize<\/li>\n<\/ul>\n<p id=\"qAdWGkO\"><img loading=\"lazy\" decoding=\"async\" width=\"1067\" height=\"404\" class=\"alignnone size-full wp-image-381 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bab431061.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bab431061.png 1067w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bab431061-300x114.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bab431061-768x291.png 768w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bab431061-1024x388.png 1024w\" sizes=\"auto, (max-width: 1067px) 100vw, 1067px\" \/><\/p>\n<h3>PING<\/h3>\n<p>Description: Checks connectivity to a specific host. Commonly used to check for liveliness, but also used to measure network latency.<\/p>\n<p>PowerShell: Test-NetConnection<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Test-NetConnection www.google.co.uk<\/li>\n<li>Test-NetConnection -ComputerName www.google.co.uk -InformationLevel Detailed<\/li>\n<li>Test-NetConnection -ComputerName www.google.co.uk | Select -ExpandProperty PingReplyDetails | FT Address, Status, RoundTripTime<\/li>\n<li>1..10 | % { Test-NetConnection -ComputerName www.microsoft.com -RemotePort 80 } | FT -AutoSize<\/li>\n<\/ul>\n<p id=\"ieATXNh\"><img loading=\"lazy\" decoding=\"async\" width=\"1103\" height=\"581\" class=\"alignnone size-full wp-image-382 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb3b6bc89.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb3b6bc89.png 1103w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb3b6bc89-300x158.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb3b6bc89-768x405.png 768w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb3b6bc89-1024x539.png 1024w\" sizes=\"auto, (max-width: 1103px) 100vw, 1103px\" \/><\/p>\n<h3>NSLOOKUP<\/h3>\n<p>Description: Name server lookup. Mostly used to find the IP address for a given DNS name (or vice-versa). Has many, many options.<\/p>\n<p>PowerShell: Resolve-DnsName<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Resolve-DnsName www.cisco.com<\/li>\n<li>Resolve-DnsName www.cisco.com -type SOA<\/li>\n<li>Resolve-DnsName cisco.com \u00a0-Server 8.8.8.8 \u2013Type A<\/li>\n<\/ul>\n<p id=\"OcorWlA\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"714\" class=\"alignnone size-full wp-image-383 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb9b951a5.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb9b951a5.png 771w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb9b951a5-300x278.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bb9b951a5-768x711.png 768w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/p>\n<p id=\"MFOMqfY\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"356\" class=\"alignnone size-full wp-image-384 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bbc0734c2.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bbc0734c2.png 766w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bbc0734c2-300x139.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/p>\n<h3>ROUTE<\/h3>\n<p>Description: Shows the IP routes in a given system (also used to add and delete routes)<\/p>\n<p>PowerShell: Get-NetRoute (also New-NetRoute and Remove-NetRoute)<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Get-NetRoute -Protocol Local -DestinationPrefix 192.168*<\/li>\n<li>Get-NetAdapter Wi-Fi | Get-NetRoute\n<p id=\"RRuSFOY\"><img loading=\"lazy\" decoding=\"async\" width=\"925\" height=\"122\" class=\"alignnone size-full wp-image-386 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc4bb2885.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc4bb2885.png 925w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc4bb2885-300x40.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc4bb2885-768x101.png 768w\" sizes=\"auto, (max-width: 925px) 100vw, 925px\" \/><\/p>\n<h3>TRACERT<\/h3>\n<p>Description: Trace route. Shows the IP route to a host, including all the hops between your computer and that host.<\/p>\n<p>PowerShell: Test-NetConnection \u2013TraceRoute<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Test-NetConnection www.google.co.uk \u2013TraceRoute<\/li>\n<li>Test-NetConnection hotmail.com -TraceRoute | Select -ExpandProperty TraceRoute | % { Resolve-DnsName $_ -type PTR -ErrorAction SilentlyContinue }<\/li>\n<\/ul>\n<p id=\"wMUZOkn\"><img loading=\"lazy\" decoding=\"async\" width=\"595\" height=\"309\" class=\"alignnone size-full wp-image-387 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc978de51.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc978de51.png 595w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bc978de51-300x156.png 300w\" sizes=\"auto, (max-width: 595px) 100vw, 595px\" \/><\/p>\n<p id=\"IAajAbu\"><img loading=\"lazy\" decoding=\"async\" width=\"1292\" height=\"604\" class=\"alignnone size-full wp-image-388 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bcbf665bb.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bcbf665bb.png 1292w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bcbf665bb-300x140.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bcbf665bb-768x359.png 768w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bcbf665bb-1024x479.png 1024w\" sizes=\"auto, (max-width: 1292px) 100vw, 1292px\" \/><\/p>\n<h3>NETSTAT<\/h3>\n<p>Description: Shows current TCP\/IP network connections.<\/p>\n<p>PowerShell: Get-NetTCPConnection<\/p>\n<p>Sample command lines:<\/p>\n<ul>\n<li>Get-NetTCPConnection | Group State, RemotePort | Sort Count | FT Count, Name \u2013Autosize<\/li>\n<li>Get-NetTCPConnection | ? State -eq Established | FT \u2013Autosize<\/li>\n<li>Get-NetTCPConnection | ? State -eq Established | ? RemoteAddress -notlike 127* | % { $_; Resolve-DnsName $_.RemoteAddress -type PTR -ErrorAction SilentlyContinue }<\/li>\n<\/ul>\n<p id=\"DTVPcKA\"><img loading=\"lazy\" decoding=\"async\" width=\"1357\" height=\"683\" class=\"alignnone size-full wp-image-389 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bd27e8804.png\" alt=\"\" srcset=\"https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bd27e8804.png 1357w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bd27e8804-300x151.png 300w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bd27e8804-768x387.png 768w, https:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902bd27e8804-1024x515.png 1024w\" sizes=\"auto, (max-width: 1357px) 100vw, 1357px\" \/><\/p>\n<\/li>\n<\/ul>\n<p>It is very interesting to know these commands in Powershell.<\/p>\n<p>I have tested some range to ping using Powershesll below command sweeps all the range of 192.168.1.0\/24<\/p>\n<div id=\"crayon-5902be6942a88595888676\" class=\"crayon-syntax crayon-theme-1c-zapros crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\">\n<div class=\"crayon-plain-wrap\"><\/div>\n<div class=\"crayon-main\">\n<table class=\"crayon-table\">\n<tbody>\n<tr class=\"crayon-row\">\n<td class=\"crayon-nums \" data-settings=\"show\">\n<div class=\"crayon-nums-content\">\n<div class=\"crayon-num\" data-line=\"crayon-5902be6942a88595888676-1\">1<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5902be6942a88595888676-2\">2<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-5902be6942a88595888676-3\">3<\/div>\n<div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5902be6942a88595888676-4\">4<\/div>\n<div class=\"crayon-num\" data-line=\"crayon-5902be6942a88595888676-5\">5<\/div>\n<\/div>\n<\/td>\n<td class=\"crayon-code\">\n<div class=\"crayon-pre\">\n<div id=\"crayon-5902be6942a88595888676-1\" class=\"crayon-line\"><span class=\"crayon-v\">$a<\/span> <span class=\"crayon-o\">=<\/span> 200<\/div>\n<div id=\"crayon-5902be6942a88595888676-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">$z<\/span> <span class=\"crayon-o\">=<\/span> 250<\/div>\n<div id=\"crayon-5902be6942a88595888676-3\" class=\"crayon-line\"><span class=\"crayon-v\">$a<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-sy\">.<\/span><span class=\"crayon-v\">$z<\/span> <span class=\"crayon-o\">|<\/span> <span class=\"crayon-st\">foreach<\/span> <span class=\"crayon-sy\">{<\/span><\/div>\n<div id=\"crayon-5902be6942a88595888676-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-h\">\u00a0\u00a0<\/span><span class=\"crayon-v\">$ip<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-s\">&#8220;192.168.1.0&#8221;<\/span> <span class=\"crayon-cn\">-replace<\/span> <span class=\"crayon-s\">&#8220;0$&#8221;<\/span><span class=\"crayon-sy\">,<\/span><span class=\"crayon-v\">$_<\/span><\/div>\n<div id=\"crayon-5902be6942a88595888676-5\" class=\"crayon-line\"><span class=\"crayon-h\">\u00a0\u00a0<\/span><span class=\"crayon-r \">Test-Connection<\/span> <span class=\"crayon-cn\">-ComputerName<\/span> <span class=\"crayon-v\">$IP<\/span> <span class=\"crayon-cn\">-Count<\/span> 1 <span class=\"crayon-cn\">-Quiet<\/span><span class=\"crayon-sy\">}<\/span><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<div class=\"crayon-line\"><\/div>\n<div class=\"crayon-line\"><strong>Test1.ps1 script will ping all the devices in the network of 192.168.1.0\/24<\/strong><\/div>\n<div class=\"crayon-line\"><\/div>\n<div class=\"crayon-line\">=================================================<\/div>\n<div id=\"crayon-5902be6942a92281230937-1\" class=\"crayon-line\"><span class=\"crayon-v\">$subnet<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-s\">&#8220;192.168.1.0&#8221;<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-2\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">$start<\/span> <span class=\"crayon-o\">=<\/span>\u00a00<\/div>\n<div id=\"crayon-5902be6942a92281230937-3\" class=\"crayon-line\"><span class=\"crayon-v\">$end<\/span> <span class=\"crayon-o\">=<\/span> 254<\/div>\n<div id=\"crayon-5902be6942a92281230937-4\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">$ping<\/span> <span class=\"crayon-o\">=<\/span> 1<\/div>\n<div id=\"crayon-5902be6942a92281230937-5\" class=\"crayon-line\"><span class=\"crayon-st\">while<\/span> <span class=\"crayon-sy\">(<\/span><span class=\"crayon-v\">$start<\/span> <span class=\"crayon-cn\">-le<\/span> <span class=\"crayon-v\">$end<\/span><span class=\"crayon-sy\">)<\/span> <span class=\"crayon-sy\">{<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-6\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-v\">$IP<\/span> <span class=\"crayon-o\">=<\/span> <span class=\"crayon-s\">&#8220;192.168.1.$start&#8221;<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-7\" class=\"crayon-line\"><span class=\"crayon-r \">Write-Host<\/span> <span class=\"crayon-s\">&#8220;Pinging $IP&#8221;<\/span> <span class=\"crayon-cn\">-ForegroundColor<\/span> <span class=\"crayon-e\">Cyan<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-8\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-r \">Test-Connection<\/span> <span class=\"crayon-cn\">-ComputerName<\/span> <span class=\"crayon-v\">$IP<\/span> <span class=\"crayon-cn\">-count<\/span> 1 <span class=\"crayon-cn\">-Quiet<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-9\" class=\"crayon-line\"><span class=\"crayon-v\">$start<\/span><span class=\"crayon-o\">++<\/span><\/div>\n<div id=\"crayon-5902be6942a92281230937-10\" class=\"crayon-line crayon-striped-line\"><span class=\"crayon-sy\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n<div class=\"crayon-line crayon-striped-line\">=================================================<\/div>\n<div class=\"crayon-line crayon-striped-line\"><\/div>\n<div class=\"crayon-line crayon-striped-line\">\n<p id=\"bLkSpwY\"><img loading=\"lazy\" decoding=\"async\" width=\"230\" height=\"274\" class=\"alignnone size-full wp-image-392 \" src=\"http:\/\/www.balajibandi.com\/wp-content\/uploads\/2017\/04\/img_5902c1b4afcd3.png\" alt=\"\" \/><\/p>\n<\/div>\n<p>Happy Labbing !<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows PowerShell \u00a0common networking commands (IPCONFIG, PING, TRACERT, ROUTE NSLOOKUP,NETSTAT) Network Engineer to trouble shoot some of Windows Servers issue apart from Networking Devices. Maybe you need to check the IP address of a machine or test if its networking connection is working. Maybe you need to see if DNS is properly configured or check [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-372","post","type-post","status-publish","format-standard","hentry","category-microsoft"],"_links":{"self":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=372"}],"version-history":[{"count":2,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions"}],"predecessor-version":[{"id":393,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/372\/revisions\/393"}],"wp:attachment":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}