locked
Problem with Test-NetConnection and suppressing progress bar RRS feed

  • Question

  • Made a script for family members to easily monitor some basic network stats and determine if their Wifi is acting up or if it's an internet issue.

    However, I can't seem to suppress the progress bar associated with test-netconnection not even the param silentlycontinue works.

    Any idea?

    PS. don't run in ISE it won't work, at least not on my system anyway.

    Function Ping
    	{
    	Clear-Host
    	#Clearing dynamic variables
    	$NetTrace, $PingJob, $PingJobResults, $Local, $ISP, $Internet = $Null
    	
    	#Populating dynamic variables
    		#Traceroute
    	$NetTrace	 	= Test-NetConnection 	$InternetTestServer -TraceRoute
    	
    		#Pinging strategic hops
    	$PingJob 		= (Test-Connection 		$NetTrace.NetRoute.NextHop, #Router/Default Gateway
    											$NetTrace.TraceRoute[$ISPHop], #Hop after router/gateway as defined in static variables
    											$NetTrace.RemoteAddress.IPAddressToString -Count $PingCount -AsJob) #Test web server as defined in static variables
    											
    		#Receiving and sorting job details									
    	$PingJobResults = Wait-Job 				$PingJob | Receive-Job | 
    											Select -Property ResponseTime, Address |
    											Sort-Object  Address, ResponseTime
    											
    		#Matching and storing results with router ip
    	$Local 			= 						$PingJobResults -Match $NetTrace.NetRoute.NextHop |
    											Measure-Object -Property ResponseTime -Average |
    											Select-Object Average, Count
    											
    		#... with ISP equipment defind hop data
    	$ISP 			= 						$PingJobResults -Match $NetTrace.TraceRoute[$ISPHop] |
    											Measure-Object -Property ResponseTime -Average |
    											Select-Object Average, Count
    	
    		#... with Specified web server
    	$Internet 		= 						$PingJobResults -Match $NetTrace.RemoteAddress.IPAddressToString |
    											Measure-Object -Property ResponseTime -Average |
    											Select-Object Average, Count
    	
    	#Interactive function menu
    	Menu
    	}
    
    
    Function Menu
    	{	
    		#Part of main menu structure
    		Clear-Host
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host ""
    		Write-host "		    	<Ping Tool>" -f green
    		Write-host ""
    		Write-host ""
    
    		#Local latency printout
    		Write-host -n "	    Local>      "
    		#Checking against defind latency warning limit 
    		IF ($Local.Average -gt $LocalLatencyWarn)
    			{
    				#Checking for dropped packets
    				IF ($Local.Count -ne $PingCount)
    					{
    						Write-host -n -f red $Local.Average
    						Write-host -n -f red "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f red $Local.Average
    						Write-host -f red "ms  "
    					}
    			}
    			
    		Else
    			{
    				#Checking for dropped packets
    				IF ($Local.Count -ne $PingCount)
    					{
    						Write-host -n -f green $Local.Average
    						Write-host -n -f green "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f green $Local.Average
    						Write-host -f green "ms  "
    					}
    			}
    
    		#ISP latency printout
    		Write-host -n "	    ISP>        "
    		#Checking against defind latency warning limit 
    		IF ($ISP.Average -gt $ISPLatencyWarn)
    			{
    				#Checking for dropped packets
    				IF ($ISP.Count -ne $PingCount)
    					{
    						Write-host -n -f red $ISP.Average
    						Write-host -n -f red "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f red $ISP.Average
    						Write-host -f red "ms  "
    					}
    			}
    			
    		Else
    			{
    				#Checking for dropped packets
    				IF ($ISP.Count -ne $PingCount)
    					{
    						Write-host -n -f green $ISP.Average
    						Write-host -n -f green "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f green $ISP.Average
    						Write-host -f green "ms  "
    					}
    			}
    		
    		#Internet latency printout
    		Write-host -n "	    Internet>   "
    		#Checking against defind latency warning limit 
    		IF ($Internet.Average -gt $InternetLatencyWarn)
    			{
    				#Checking for dropped packets
    				IF ($Internet.Count -ne $PingCount)
    					{
    						Write-host -n -f red $Internet.Average
    						Write-host -n -f red "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f red $Internet.Average
    						Write-host -f red "ms  "
    					}
    			}
    			
    		Else
    			{
    				#Checking for dropped packets
    				IF ($Internet.Count -ne $PingCount)
    					{
    						Write-host -n -f green $Internet.Average
    						Write-host -n -f green "ms  "
    						Write-host  -f red -b white "<Packet loss detected!>" 
    					}
    					
    				Else
    					{
    						Write-host -n -f green $Internet.Average
    						Write-host -f green "ms  "
    					}
    			}
    		
    		#More of main menu structure
    		Write-host ""
    		Write-host "	    Autopolling	<Coming Soon>"
    		Write-host "	    Re-Test	<Space> or <Enter>"
    		Write-host "	    Exit	<Esc>   or <Backspace>"
    		
    		#Waiting for input
    		$answer = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    		
    		#Input triggers
    		IF (($BCKspc -eq $answer.Virtualkeycode)-or
    			($ESCkey -eq $answer.Virtualkeycode))
    		{
    			Exit
    		}
    		
    		IF (($Enter -eq $answer.Virtualkeycode)-or
    			($Space -eq $answer.Virtualkeycode))
    		{
    			Ping
    		}		
    		
    		Else 
    		{
    			#Looping back to menu in absence of assigned input
    			Menu
    		}
    	}
    
    #Key Assignments
    	$ESCkey = (27)
    	$BCKspc = (8)
    	$Enter 	= (13)
    	$Space	= (32)
    
    #Console Parameters
    	[console]::WindowHeight		= '22'
    	[console]::WindowWidth		= '60'
    	[console]::BufferHeight		= '22'
    	[console]::BufferWidth		= '60'
    	[console]::CursorVisible	= $False
    	[console]::Title			= 'Ping Tool'
    
    #Defining Static Variables
    	$LocalLatencyWarn		= '5'
    	$ISPLatencyWarn 		= '55'
    	$InternetLatencyWarn	= '85'
    	$PingCount				= '5'
    	$ISPHop					= '2'
    	$InternetTestServer		= 'Google.com'
    	$AutopollFrequency		= '15'
    
    #Starting the tool.	
    & "Ping"


    • Edited by -Jason- Monday, February 5, 2018 7:54 PM
    Monday, February 5, 2018 7:53 PM

Answers

  • $Global:ProgressPreference = 'SilentlyContinue'

    \_(ツ)_/

    • Marked as answer by -Jason- Monday, February 5, 2018 8:44 PM
    Monday, February 5, 2018 8:38 PM
  • It has been documented as long as there has been a progress indicator:

    help about_Preference_Variables


    \_(ツ)_/

    • Marked as answer by -Jason- Monday, February 5, 2018 8:44 PM
    Monday, February 5, 2018 8:41 PM

All replies

  • I'm going to say that you cannot.

    I tried

    Test-NetConnection google.com -InformationLevel Quiet

    Test-NetConnection google.com | Out-Null

    And the progress bar still shows


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Monday, February 5, 2018 8:00 PM
  • Yeah and it doesn't even support -asjob so it's very limited :/
    Monday, February 5, 2018 8:10 PM
  • This is why you need to learn basic PowerShell.

    $ProgressPreference = 'SilentlyContinue'
    Test-NetConnection omega


    \_(ツ)_/

    • Proposed as answer by clayman2 Monday, February 5, 2018 8:18 PM
    Monday, February 5, 2018 8:16 PM
  • This is why you need to learn basic PowerShell.

    $ProgressPreference = 'SilentlyContinue'
    Test-NetConnection omega


    \_(ツ)_/

    When was $ProgressPreference introduced? I haven't read anything since PS 2.0 and really don't remember that variable.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Monday, February 5, 2018 8:19 PM
  • Yup it works as a stand alone command but in the scope of the script I posted it does not hence asking for input.
    Monday, February 5, 2018 8:20 PM
  • $Global:ProgressPreference = 'SilentlyContinue'

    \_(ツ)_/

    • Marked as answer by -Jason- Monday, February 5, 2018 8:44 PM
    Monday, February 5, 2018 8:38 PM
  • It has been documented as long as there has been a progress indicator:

    help about_Preference_Variables


    \_(ツ)_/

    • Marked as answer by -Jason- Monday, February 5, 2018 8:44 PM
    Monday, February 5, 2018 8:41 PM
  • It works thanks! :)
    Monday, February 5, 2018 8:45 PM