How to make a script in powershell that returns

Sandro Alves 41 Reputation points
2022-11-14T14:20:18.82+00:00

Hi,

I have a command that when executed only ends after (ctrl+c).

It returns like this:

C:\Temp\ping-sso>PingWatch.exe
11/14/2022 11:15:14,https://www.google.com/,OK,749ms
11/14/2022 11:15:15,https://www.google.com/,OK,190ms
11/14/2022 11:15:16,https://www.google.com/,OK,205ms
11/14/2022 11:15:17,https://www.google.com/,OK,200ms
^C
C:\Temp\ping-sso>

How do I, for example, return the fourth result which is (200)? Just the value.

Thanks.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,410 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,430 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,441 Reputation points
    2022-11-14T19:33:32.043+00:00

    Don't use PingWatch.exe.

    1..4 | foreach {  
        $wr =  Measure-Command {  
            Invoke-WebRequest https://www.google.com   
        }  
        "Test {0} took {1}ms." -f $_, $wr.Milliseconds  
    }  
    "The final test took {0}ms." -f $wr.Milliseconds