locked
Select-Object -Property Question RRS feed

  • Question

  • I want to return only the "Time(ms)" value from the command:

    Test-Connection -Count 1 -ComputerName "192.168.1.1" 

    which returns:

    Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
    ------        -----------     -----------      -----------                              -----    --------
    mysource      192.168.1.1     192.168.1.1                                               32       1

    When I run:

    Test-Connection -Count 1 -ComputerName "192.168.1.1" | Select-Object -Property Time`(ms`)

    I get:

    Time(ms)

    --------

    How do I get just the "1"




    • Edited by mimaki Friday, February 23, 2018 8:04 PM
    Friday, February 23, 2018 8:03 PM

All replies

  • Test-Connection -Count 1 -ComputerName 192.168.1.1 | Select-Object -Property'Time (ms)'

    Quotes needed when spaces are present.

    A better choice:

    (Test-Connection -Count 1 -ComputerName 192.168.1.1).ResponseTime

    "Time (ms)" is a decorated result that is not available to a "select-object" statement.

    Test-Connection -Count 1 -ComputerName 192.168.1.1| Get-Member


    \_(ツ)_/

    Friday, February 23, 2018 8:13 PM
  • Yes, it's one of those weird commands where the column headers aren't necessarily the properties.  Pipe the command to format-list * to see all the properties.


    Test-Connection -Count 1 192.168.1.1 | fl *


    • Edited by JS2010 Friday, February 23, 2018 11:03 PM
    Friday, February 23, 2018 9:13 PM
  • Much more details along with below answers.

    Time(ms) is just the column header shown in the output when its thrown to the console. PowerShell console outputs are finally gone through default formatting every time until we use any of the Formatting cmdlets. Here output of Test-Connection is also gone through the default formatting and the actual property ResponseTime  is altered via the default formatting for the output type System.Management.ManagementObject#root\cimv2\Win32_PingStatus you can see that in the formatting file under the $PSHome path.

    see below for this type.


    Regards kvprasoon

    Saturday, February 24, 2018 8:08 PM