Using Test-Netconnection from dashboard and returning results

I would like to be able to run two tests from my dashboard. a ping and a trace route. I have an input that takes the variable and adds it to the test-netconnection string but i can’t get it to return any date.

If i run the test connection command manually from the cmd line it works but when going through the dashboard i get this error " Error getting value from ‘Address’ on ‘System.Net.IPAddress’."

Anyone have any ideas. Thanks

New-UDInput -Title “Network Tester. Please Enter Destination Server Name For The Server You Want To Ping. (Source is Currently AWS VDI)” -Endpoint {
param(
[string]$destination
)

New-UDInputAction -Content {
    New-UDElement -Tag 'div'  -Content { 

        New-UDTable -Title 'Test Results' -Headers  @('RemoteAddress' ,'InterfaceAlias', 'SourceAddress' ,'PingSucceeded') -Endpoint{ 
        Test-NetConnection -ComputerName $destination | Select-Object RemoteAddress, InterfaceAlias, SourceAddress, PingSucceeded | Out-UDTableData -Property('RemoteAddress' ,'InterfaceAlias', 'SourceAddress' ,'PingSucceeded')
                      }

####End Network Tester####

    }#close inpuct action 

}#close input

}#close input

Hi gerard, please try to encompass your entire code block in the preformatted text.
It make it easier for us to help you.

The reason you get this error is because Out-UDTableData accept strings values only.

When you give him a IPAddress, which is the object Type Test-NetConnection RemoteAddress returns, it does not know how to translate it.

To fix the error, you can use calculated properties.

New-UDInput -Title "Network Tester. Please Enter Destination Server Name For The Server You Want To Ping. (Source is Currently AWS VDI)" -Endpoint {
        param(
            [string]$destination
        )
        
        New-UDInputAction -Content {
            New-UDElement -Tag 'div'  -Content { 

                New-UDTable -Title 'Test Results' -Headers  @('RemoteAddress' , 'InterfaceAlias', 'SourceAddress' , 'PingSucceeded') -Endpoint { 
                    Test-NetConnection -ComputerName $destination | 
                    Select-Object @{name = 'RemoteAddress'; expression = { $_.RemoteAddress.ipaddresstostring | Out-String } },
                     InterfaceAlias,
                      @{name = 'SourceAddress'; expression = { $_.SourceAddress.ipaddress} }, 
                      @{name='PingSucceeded';expression={[String]$_.PingSucceeded}} | 
                      Out-UDTableData -Property @('RemoteAddress' , 'InterfaceAlias', 'SourceAddress' , 'PingSucceeded')
                }
                ####End Network Tester####

            }#close inpuct action 

        }#close input
    }#close input

Good to note:

You can see in the code I provided that I used 2 different methods for RemoteAddress and SourceAddress.

By running your Test-NetConnection alone, you can view (if you use .gettype() on the individual properties) that the

  • RemoteAddress is a IPAddress object
    -SourceAddress is a CIMInstance

Ultimately, I also had to convert the PingSucceeded from Boolean to string for it to be displayed since even though it did not cause any error, the boolean representation was not displayed in the table.

If you are unfamiliar with calculated properties, see :
4Sysops — Add a calculated property with Select-Object in PowerShell

Thank you so much for the help. if i run test-netconnection | select-object -property *
i see all the options i can pick to parse like RemoteAddress and InterfaceAlias but how
do i tell what types they are?

For example if i want PingReplyDetails i can see the details but how do i get the type.
PingReplyDetails : System.Net.NetworkInformation.PingReply

Thanks again

If you convert it to json it’s easier to visualize.
test-netconnection google.com | convertto-json
Anything without children usually works.

Do you just mean its easier to read that way? if i do the convert to json i see this but it doesnt mention what the type is. I apologize for being so dense. I am just figuring a lot of this stuff out.

“PingReplyDetails”: {
“Status”: 0,
“Address”: {
“Address”: null,
“AddressFamily”: 23,
“ScopeId”: 0,
“IsIPv6Multicast”: false,
“IsIPv6LinkLocal”: false,
“IsIPv6SiteLocal”: false,
“IsIPv6Teredo”: false,
“IsIPv4MappedToIPv6”: false
},
“RoundtripTime”: 36,
“Options”: null,
“Buffer”: [

No worries man, if you have no prior experience with json it might actually be worse.
image

Look at “AllNameResolutionResults” which returns an array of values.
“IsAdmin” and “NetworkIsolationContext” only has a single string-able value.

I got it. thanks for all the help…

                    New-UDTable -Title 'Test Results' -Headers  @('RemoteAddress' , 'InterfaceAlias', 'SourceAddress' , 'PingSucceeded', 'PingReplyDetails') -Endpoint {
                Test-NetConnection -ComputerName $destination | Select-Object `
                @{name = 'RemoteAddress'; expression = { $_.RemoteAddress.ipaddresstostring} }, `
                InterfaceAlias, `
                @{name = 'SourceAddress'; expression={ $_.SourceAddress.ipaddress} }, `
                @{name = 'PingSucceeded'; expression={[String]$_.PingSucceeded} }, `
                @{name = 'PingReplyDetails' ; expression={$_.PingReplyDetails.RoundtripTime.ToString() + " ms"}} |  Out-UDTableData -Property @('RemoteAddress' , 'InterfaceAlias', 'SourceAddress' , 'PingSucceeded', 'PingReplyDetails')`
                }
2 Likes