{"id":463,"date":"2018-12-10T08:00:26","date_gmt":"2018-12-10T14:00:26","guid":{"rendered":"https:\/\/practicalpowershell.com\/?p=463"},"modified":"2020-03-13T21:54:18","modified_gmt":"2020-03-14T03:54:18","slug":"connectivity-testing","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/connectivity-testing\/","title":{"rendered":"Connectivity Testing"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?resize=150%2C150&#038;ssl=1\" alt=\"\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-464\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?resize=100%2C100&amp;ssl=1 100w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a>When writing scripts that download files or scrape websites for content, one of the weaknesses of such scripts comes down to whether or not the script can connect to the Internet and download the files needed. PowerShell has many methods for determining whether a connection can be made or not. We&#8217;ll explore these possibilities.<BR><br \/>\n<em>Test-Connection<\/em><BR><br \/>\nWithin PowerShell there is a cmdlet called Test-Connection. This can be used to reach out to a server to see if it is available. There are quite a few options that can be used with this cmdlet. We can specify these options:<BR><br \/>\n<em>BufferSize <\/em>&#8211; default is 32 (bytes)<br \/>\n<em>ComputerName<\/em> &#8211; what server to check<br \/>\n<em>Count <\/em>&#8211; how many echo requests to send<br \/>\n<em>Credential <\/em>&#8211; if credentials are needed to send a ping request<br \/>\n<em>DcomAuthentication<\/em> &#8211; choose the level of authentication that WMI uses<br \/>\n<em>Delay<\/em> &#8211; delay between pings<br \/>\n<em>Protocol <\/em>&#8211; Dcom and Wsman are allowable choices<br \/>\n<em>Quiet<\/em> &#8211; Suppresses errors<br \/>\n<em>Source<\/em> &#8211; where to originate ping<br \/>\n<em>ThrottleLimit<\/em> &#8211; specifies a concurrent connection limit &#8211; 32 is the default.<br \/>\n<em>TimeToLive <\/em>&#8211; default is 80 seconds<BR><br \/>\nFor basic connection testing, we should be able to run a cmdlet like this:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nTest-Connection -ComputerName &lt;IP or Computer Name&gt;&lt;BR&gt;<br \/>\n[\/sourcecode]<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-01.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-01.jpg?resize=640%2C111&#038;ssl=1\" alt=\"\" width=\"640\" height=\"111\" class=\"aligncenter size-full wp-image-465\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-01.jpg?w=730&amp;ssl=1 730w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-01.jpg?resize=300%2C52&amp;ssl=1 300w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-01.jpg?resize=600%2C104&amp;ssl=1 600w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\nHow can we use this in a check for script processing:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$Bad=0<br \/>\n$Good=0<br \/>\nTry {<br \/>\n$Test = Test-Connection -ComputerName 192.168.0.254 -ErrorAction STOP<br \/>\n$Good++<br \/>\n} Catch {<br \/>\n$Bad++<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nIf the connection is successful, then $Good would equal 1 and if it is not successful, $Bad would equal 1.<BR><br \/>\nSuccessful Connection:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?resize=640%2C61&#038;ssl=1\" alt=\"\" width=\"640\" height=\"61\" class=\"aligncenter size-full wp-image-466\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?w=796&amp;ssl=1 796w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?resize=300%2C29&amp;ssl=1 300w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?resize=768%2C73&amp;ssl=1 768w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-02.jpg?resize=600%2C57&amp;ssl=1 600w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\nUnsuccessful Connection:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?resize=640%2C60&#038;ssl=1\" alt=\"\" width=\"640\" height=\"60\" class=\"aligncenter size-full wp-image-467\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?w=794&amp;ssl=1 794w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?resize=300%2C28&amp;ssl=1 300w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?resize=768%2C72&amp;ssl=1 768w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-03.jpg?resize=600%2C56&amp;ssl=1 600w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\n<em>Networking Check<\/em><BR><br \/>\nWe can use this cmdlet to check network connections of a computer. Most computers will only have one NIC. When we run the cmdlet &#8211; Get-NetConnectionProfile &#8211; we see this result:<BR><br \/>\nSample Output:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-04.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-04.jpg?resize=296%2C124&#038;ssl=1\" alt=\"\" width=\"296\" height=\"124\" class=\"aligncenter size-full wp-image-468\" \/><\/a><br \/>\nIf we are specifically looking for Internet connectivity, then we can specifically look at the IPv4Connectivity value. On a server that can reach the Internet, the value would indeed be &#8216;Internet&#8217; as show above. If the network connection is missing it&#8217;s default gateway, then we should get a different result:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-05.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-05.jpg?resize=358%2C98&#038;ssl=1\" alt=\"\" width=\"358\" height=\"98\" class=\"aligncenter size-full wp-image-469\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-05.jpg?w=358&amp;ssl=1 358w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-05.jpg?resize=300%2C82&amp;ssl=1 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/a><br \/>\nThis test isn&#8217;t always the best test for Internet connectivity, but if the connection is valid and there is a default gateway, we should be able to check it with this:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$Internetaccess = (Get-NetConnectionProfile -IPv4Connectivity Internet).ipv4connectivity<br \/>\n[\/sourcecode]<br \/>\nIf $InternetAccess = &#8216;Internet&#8217; then there is a valid connection and downloads should work.<BR><br \/>\n<em>Ping Test (with PowerShell)<\/em><BR><br \/>\nA common tool for troubleshooting in networking is PING. It can be used to assess whether a connection could be made to a remote device. If that device can be reached with ICMP packets, then this test will be valid. A common blocker for this test are firewalls and servers that block ICMP packet types.<BR><br \/>\n<em>Ping DC01<\/em><br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-06.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-06.jpg?resize=466%2C188&#038;ssl=1\" alt=\"\" width=\"466\" height=\"188\" class=\"aligncenter size-full wp-image-470\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-06.jpg?w=466&amp;ssl=1 466w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-06.jpg?resize=300%2C121&amp;ssl=1 300w\" sizes=\"auto, (max-width: 466px) 100vw, 466px\" \/><\/a><br \/>\nAs we can see, in this case a ping test to an internal server works. We can also perform the same test to a known Internet entity like Google&#8217;s DNS servers:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-07.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-07.jpg?resize=474%2C190&#038;ssl=1\" alt=\"\" width=\"474\" height=\"190\" class=\"aligncenter size-full wp-image-471\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-07.jpg?w=474&amp;ssl=1 474w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-07.jpg?resize=300%2C120&amp;ssl=1 300w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><br \/>\n<em>Test-NetConnect<\/em><BR><br \/>\nPowerShell provides a cmdlet that is much more advanced than PING, we have Test-NetConnection. From Microsoft:<br \/>\n&#8220;The Test-NetConnection cmdlet displays diagnostic information for a connection. It supports ping test, TCP test, route tracing, and route selection diagnostics. Depending on the input parameters, the output can include the DNS lookup results, a list of IP interfaces, IPsec rules, route\/source address selection results, and\/or confirmation of connection establishment.&#8221;<br \/>\nFirst, the &#8216;PING replacement&#8217;:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nTest-NetConnect DC01<br \/>\n[\/sourcecode]<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-08.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-08.jpg?resize=444%2C116&#038;ssl=1\" alt=\"\" width=\"444\" height=\"116\" class=\"aligncenter size-full wp-image-472\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-08.jpg?w=444&amp;ssl=1 444w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-08.jpg?resize=300%2C78&amp;ssl=1 300w\" sizes=\"auto, (max-width: 444px) 100vw, 444px\" \/><\/a><br \/>\nSame command, but to an external destination, again using Google&#8217;s DNS server as an example:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nTest-NetConnect 8.8.8.8<br \/>\n[\/sourcecode]<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-09.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-09.jpg?resize=324%2C120&#038;ssl=1\" alt=\"\" width=\"324\" height=\"120\" class=\"aligncenter size-full wp-image-473\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-09.jpg?w=324&amp;ssl=1 324w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-09.jpg?resize=300%2C111&amp;ssl=1 300w\" sizes=\"auto, (max-width: 324px) 100vw, 324px\" \/><\/a><br \/>\nTesting Port Availability:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-10.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-10.jpg?resize=406%2C312&#038;ssl=1\" alt=\"\" width=\"406\" height=\"312\" class=\"aligncenter size-full wp-image-474\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-10.jpg?w=406&amp;ssl=1 406w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-10.jpg?resize=300%2C231&amp;ssl=1 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/a><br \/>\n<em>Logging level:<\/em><BR><br \/>\nWhile the detailed level setting for &#8216;InformationLevel&#8217; will work for troubleshooting purposes, when it comes to practical application in a script, the &#8216;Quiet&#8217; setting is a much better match. <BR><em>Sample output:<\/em><BR><br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-11.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-11.jpg?resize=586%2C328&#038;ssl=1\" alt=\"\" width=\"586\" height=\"328\" class=\"aligncenter size-full wp-image-475\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-11.jpg?w=586&amp;ssl=1 586w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-11.jpg?resize=300%2C168&amp;ssl=1 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/a><br \/>\n<em>Why Quiet is better?<\/em><BR><br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$PortTest = Test-NetConnection ex04 -Port 80 -InformationLevel Quiet<br \/>\nIf ($PortTest) {Write-host &quot;Server EX04 has port 80 open!&quot; -ForegroundColor Cyan}<br \/>\n[\/sourcecode]<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-12.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-12.jpg?resize=640%2C56&#038;ssl=1\" alt=\"\" width=\"640\" height=\"56\" class=\"aligncenter size-full wp-image-476\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-12.jpg?w=734&amp;ssl=1 734w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-12.jpg?resize=300%2C26&amp;ssl=1 300w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-12.jpg?resize=600%2C52&amp;ssl=1 600w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><br \/>\n<em>Related Connection Testing<\/em><BR><br \/>\nFor Windows servers, we can also use a WMI or CIM connection to see if a server is reachable. Remember that if a server is on the domain, both of these methods should work. However if a server is not on the domain, It is easier to use WMI cmdlets. If there is a need to use CIM, then a new CIM session needs to be created with the &#8216;New-CIMSession&#8217; cmdlet which is similar to the New-PSSession cmdlet for connecting to remote machines via PowerShell.<br \/>\nIn order to test a connect, we can start with CIM (without using New-CIMSession) and then WMI to test whether a server is up. We can do so with code like this:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n# All Domain Controller<br \/>\n$ADServers = (Get-ADDomainController -Filter *).name<br \/>\n# All Exchange Servers<br \/>\n$ExchangeServers = (Get-ExchangeServer).Name<br \/>\nFunction ConnectionTest ($Server,$Type) {<br \/>\nTry {<br \/>\n$ConnectionTest = Get-WmiObject -Class Win32_Service -ComputerName $Server -ErrorAction STOP<br \/>\nwrite-host &quot;The $Type server $Server is Accessible!&quot; -ForegroundColor Green<br \/>\n} Catch {<br \/>\nWrite-host &quot;The $Type server $Server is inaccessible!&quot; -ForegroundColor Red<br \/>\n}<br \/>\n}<br \/>\nForeach ($ADServer in $ADServers) {<br \/>\n$Type = &quot;Domain Controller&quot;<br \/>\nConnectionTest $ADServer $Type<br \/>\n}<br \/>\n# Test<br \/>\nForeach ($ExchangeServer in $ExchangeServers) {<br \/>\n$Type = &quot;Exchange&quot;<br \/>\nConnectionTest $ExchangeServer $Type<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nWhich produces this output:<br \/>\n<a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-13.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-13.jpg?resize=438%2C128&#038;ssl=1\" alt=\"\" width=\"438\" height=\"128\" class=\"aligncenter size-full wp-image-477\" srcset=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-13.jpg?w=438&amp;ssl=1 438w, https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/TestConnection-13.jpg?resize=300%2C88&amp;ssl=1 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/a><br \/>\n<em>Practical PowerShell Usages?<\/em><BR><br \/>\nIt is one thing to test a connection, but an entirely different concept is to use that information to make a decision. For a script needing to connect to a remote computer, it would be ideal to check that server first before connecting and registering an error if the test connection fails. For a script that would need to download updates or software from the Internet, confirming access was there prior would be good as well.<BR><br \/>\n<em>How can we accomplish this?<\/em><BR><br \/>\nInternet Access Test and Decision Making:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n$InternetAccess = (Get-NetConnectionProfile -IPv4Connectivity Internet).ipv4connectivity<br \/>\nIf ($InternetAccess -eq &quot;Internet&quot;) {<br \/>\n&lt;perform some task here&gt;<br \/>\n} Else {<br \/>\nWrite-Host &quot;No Internet connection could be found. Please fix and rerun this script&quot;<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nServer Connection Test and Decision Making<br \/>\nIn the below code, PowerShell will first attempt to connect via CIM. If this fails, the $TryWMI variable will be set to $true and this trigger the WMI code next. If that fails, we are notified of this failure.<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nTry {<br \/>\n$RAM = (Get-CIMInstance -ComputerName DC01 -ClassName WIN32_PhysicalMemory -ErrorAction STOP | Measure-Object -Property Capacity -Sum).Sum\/1GB<br \/>\n} Catch {<br \/>\n$TryWMI = $True<br \/>\n}<br \/>\nIf ($TryWMI) {<br \/>\nTry {<br \/>\n$RAM = (Get-WMIObject -Computer DC01 -Class WIN32_PhysicalMemory -ErrorAction STOP | Measure-Object -Property Capacity -Sum).Sum\/1GB<br \/>\n} Catch {<br \/>\nWrite-host &quot;The server DC01 could not be queried&quot; -ForegroundColor Red<br \/>\n}<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When writing scripts that download files or scrape websites for content, one of the weaknesses of such scripts comes down to whether or not the script can connect to the Internet and download the files needed. PowerShell has many methods for determining whether a connection can be made or not. We&#8217;ll explore these possibilities. Test-Connection [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-463","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Connectivity Testing - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/connectivity-testing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Connectivity Testing - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"When writing scripts that download files or scrape websites for content, one of the weaknesses of such scripts comes down to whether or not the script can connect to the Internet and download the files needed. PowerShell has many methods for determining whether a connection can be made or not. We&#8217;ll explore these possibilities. Test-Connection [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/connectivity-testing\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2018-12-10T14:00:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-14T03:54:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network-150x150.jpg\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"Connectivity Testing\",\"datePublished\":\"2018-12-10T14:00:26+00:00\",\"dateModified\":\"2020-03-14T03:54:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/\"},\"wordCount\":1084,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Network-150x150.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/\",\"name\":\"Connectivity Testing - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Network-150x150.jpg\",\"datePublished\":\"2018-12-10T14:00:26+00:00\",\"dateModified\":\"2020-03-14T03:54:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Network.jpg?fit=247%2C204&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/Network.jpg?fit=247%2C204&ssl=1\",\"width\":247,\"height\":204},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/connectivity-testing\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Connectivity Testing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Connectivity Testing - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/connectivity-testing\/","og_locale":"en_US","og_type":"article","og_title":"Connectivity Testing - Practical PowerShell","og_description":"When writing scripts that download files or scrape websites for content, one of the weaknesses of such scripts comes down to whether or not the script can connect to the Internet and download the files needed. PowerShell has many methods for determining whether a connection can be made or not. We&#8217;ll explore these possibilities. Test-Connection [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/connectivity-testing\/","og_site_name":"Practical PowerShell","article_published_time":"2018-12-10T14:00:26+00:00","article_modified_time":"2020-03-14T03:54:18+00:00","og_image":[{"url":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network-150x150.jpg","type":"","width":"","height":""}],"author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"Connectivity Testing","datePublished":"2018-12-10T14:00:26+00:00","dateModified":"2020-03-14T03:54:18+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/"},"wordCount":1084,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"image":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network-150x150.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/connectivity-testing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/","url":"https:\/\/practicalpowershell.com\/connectivity-testing\/","name":"Connectivity Testing - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#primaryimage"},"image":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network-150x150.jpg","datePublished":"2018-12-10T14:00:26+00:00","dateModified":"2020-03-14T03:54:18+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/connectivity-testing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#primaryimage","url":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?fit=247%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/Network.jpg?fit=247%2C204&ssl=1","width":247,"height":204},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/connectivity-testing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"Connectivity Testing"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=463"}],"version-history":[{"count":2,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/463\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/463\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}