none
problem with format-table cmdlet

    Question

  • Hi

    considering the following screenshots i need to know where i am wrong ? why no information is displayed under destination and time columns ?


    even using -Autosize didn't have any effect !

    Thanks in advanced

    Monday, April 15, 2019 7:17 PM

Answers

All replies

  • Yeah, the column headings from the format file don't match up with the properties.  It's not great.  You want Address and ResponseTime in this case.  Findstr with two words does an either/or match.

    PS C:\users\me> $a = test-connection yahoo.com -count 1
    PS C:\users\me> $a 

    Source        Destination     IPV4Address      IPV6Address       Bytes    Time(ms)
    ------        -----------     -----------      -----------       -----    --------
    MYCOMP        yahoo.com       72.30.35.9                         32       10


    PS C:\users\me> $a | fl * | findstr 'yahoo.com 10'

    Address                        : yahoo.com
    ResponseTime                   : 10

    Monday, April 15, 2019 7:26 PM
  • "Destination" is a synthetic property produced by the type formatter. It is not part of the result object:

    Do the following to understand the object:

    Test-Connection 4.2.2.2 -Count 1 | select *

    Do the following to discover the object type:

    Test-Connection 4.2.2.2 -Count 1 | gm

    The type is "Win32_PingStatus" - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/wmipicmp/win32-pingstatus


    \_(ツ)_/

    Monday, April 15, 2019 7:41 PM
    Moderator
  • The format definitions for the output are here:

    C:\Windows\System32\WindowsPowerShell\v1.0\DotNetTypes.format.ps1xml

    This is how PowerShell determines the output format for an object when listed to the console or saved to a file.


    \_(ツ)_/

    Monday, April 15, 2019 7:58 PM
    Moderator
  • Too bad this doesn't work, unless you save the xml to a file.

    # ManagementObject

    # Destination = Address
    # Time = ResponseTime (width 12)

    $testconnectionformat = @'
    <?xml version="1.0" encoding="utf-8" ?>
    <Configuration>
    <ViewDefinitions>
    <View>
     <Name>System.Management.ManagementObject#root\cimv2\Win32_PingStatus</Name>   
    <ViewSelectedBy>
    <TypeName>System.Management.ManagementObject#root\cimv2\Win32_PingStatus</TypeName>
    </ViewSelectedBy>
              <TableControl>
                    <TableHeaders>
                        <TableColumnHeader>
                            <Label>Source</Label>
                            <Width>13</Width>
                        </TableColumnHeader>
                        <TableColumnHeader>
                    <Label>Address</Label>
                            <Width>15</Width>
                        </TableColumnHeader>
                          <TableColumnHeader>
            <Label>IPV4Address</Label>
                            <Width>16</Width>
                        </TableColumnHeader>
                          <TableColumnHeader>
            <Label>IPV6Address</Label>
                            <Width>40</Width>
                        </TableColumnHeader>
                        <TableColumnHeader>
    <Label>Bytes</Label>
                            <Width>8</Width>
                        </TableColumnHeader>
                        <TableColumnHeader>
                    <Label>ResponseTime</Label>
                            <Width>12</Width>
                        </TableColumnHeader>
                      </TableHeaders>
                    <TableRowEntries>
                        <TableRowEntry>
                            <TableColumnItems>
                                <TableColumnItem>
                                    <PropertyName>__Server</PropertyName>
                                </TableColumnItem>
                                <TableColumnItem>
                                    <PropertyName>Address</PropertyName>
                                </TableColumnItem>
                                <TableColumnItem>
                                    <PropertyName>IPV4Address</PropertyName>
                                </TableColumnItem>
                                <TableColumnItem>
                                    <PropertyName>IPV6Address</PropertyName>
                                </TableColumnItem>
                                <TableColumnItem>
                                    <PropertyName>BufferSize</PropertyName>
                                </TableColumnItem>
                                <TableColumnItem>
                                    <PropertyName>ResponseTime</PropertyName>
                                </TableColumnItem>                            
                            </TableColumnItems>
                        </TableRowEntry>
                     </TableRowEntries>
                </TableControl>        
      </View>
    </ViewDefinitions>
    </Configuration>
    '@

    update-formatdata -prependpath variable:testconnectionformat

    update-formatdata : Cannot open the file because the current provider is "Microsoft.PowerShell.Core\Variable", and this command requires a file.
    At C:\users\admin\fixping.ps1:72 char:1
    + update-formatdata -prependpath variable:testconnectionformat
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Update-FormatData], PSInvalidOperationException
        + FullyQualifiedErrorId : FormatPrependPathException,Microsoft.PowerShell.Commands.UpdateFormatDataCommand


    test-connection yahoo.com -count 1

    Source        Address         IPV4Address      IPV6Address     Bytes    ResponseTime
    ------        -------         -----------      -----------     -----    ------------
    MYCOMP        yahoo.com       98.137.246.7                     32       72

    • Edited by JS2010 Monday, April 22, 2019 12:34 PM
    Tuesday, April 16, 2019 2:34 PM
  • Thanks to All

    i learned useful notes

    Saturday, April 20, 2019 6:40 PM