Run a ping and display results in table

This topic contains 10 replies, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 1 year, 10 months ago.

  • Author
    Posts
  • #29209
    Profile photo of 37mm
    37mm
    Participant

    get-adcomputer -filter * -Property * | select name,dnshostname,operatingsystem,operatingsystemservicepack,ipv4address,lastlogondate,logoncount |sort lastlogondate -Descending

    I run this, then convert to html.

    What I want to do and don't really know where to start, Is I would like to ping the ipv4 address and append the results on the table. Can I do this? or rather where do I start?

    Thanks in advance!

  • #29210
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    You could create a calculated property using your select object

    get-adcomputer * -Property * | Select-Object name,dnshostname,operatingsystem,operatingsystemservicepack,ipv4address,lastlogondate,logoncount, @{label = "PingResults"; Expression = {Ping $_.ipv4address}} |sort lastlogondate -Descending
    

    That is assuming you are specific about using "ping". You can also use the powershell test-connection cmdlet.

    get-adcomputer * -Property * | Select-Object name,dnshostname,operatingsystem,operatingsystemservicepack,ipv4address,lastlogondate,logoncount, @{label = "PingResults"; Expression = {Test-Connection $_.ipv4address}} |sort lastlogondate -Descending
    
  • #29211
    Profile photo of 37mm
    37mm
    Participant

    Ok thanks alot brother!

    But how do i trim the results to just show the latency or is it better do tnc -informationlevel quiet

    Or is it possible to trim the results of the tnc command to show the latency ?

  • #29212
    Profile photo of 37mm
    37mm
    Participant

    Running it with TNC -informationlevel quiet gives me the desired results, Thanks again. But just wondering if I wanted to select certain outputs of the TNC to just show the latency how would I do this? If it is possible?

  • #29213
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    The Test-Connection cmdlet returns objects for each ping result. You can simply pipe that into a select statement and pick out the properties you want to keep


    PSComputerName : Workstation1
    IPV4Address : 8.8.8.8
    IPV6Address :
    __GENUS : 2
    __CLASS : Win32_PingStatus
    __SUPERCLASS :
    __DYNASTY : Win32_PingStatus
    __RELPATH : Win32_PingStatus.Address="8.8.8.8",BufferSize=32,NoFragmentation=FALSE,RecordRoute=0,R
    esolveAddressNames=FALSE,SourceRoute="",SourceRouteType=0,Timeout=4000,TimestampRoute=
    0,TimeToLive=80,TypeofService=0
    __PROPERTY_COUNT : 24
    __DERIVATION : {}
    __SERVER : Workstation1
    __NAMESPACE : root\cimv2
    __PATH : \\Workstation1\root\cimv2:Win32_PingStatus.Address="8.8.8.8",BufferSize=32,NoFragmenta
    tion=FALSE,RecordRoute=0,ResolveAddressNames=FALSE,SourceRoute="",SourceRouteType=0,Ti
    meout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0
    Address : 8.8.8.8
    BufferSize : 32
    NoFragmentation : False
    PrimaryAddressResolutionStatus : 0
    ProtocolAddress : 8.8.8.8
    ProtocolAddressResolved :
    RecordRoute : 0
    ReplyInconsistency : False
    ReplySize : 32
    ResolveAddressNames : False
    ResponseTime : 30
    ResponseTimeToLive : 49
    RouteRecord :
    RouteRecordResolved :
    SourceRoute :
    SourceRouteType : 0
    StatusCode : 0
    Timeout : 4000
    TimeStampRecord :
    TimeStampRecordAddress :
    TimeStampRecordAddressResolved :
    TimestampRoute : 0
    TimeToLive : 80
    TypeofService : 0
    Scope : System.Management.ManagementScope
    Path : \\Workstation1\root\cimv2:Win32_PingStatus.Address="8.8.8.8",BufferSize=32,NoFragmenta
    tion=false,RecordRoute=0,ResolveAddressNames=false,SourceRoute="",SourceRouteType=0,Ti
    meout=4000,TimestampRoute=0,TimeToLive=80,TypeofService=0
    Options : System.Management.ObjectGetOptions
    ClassPath : \\Workstation1\root\cimv2:Win32_PingStatus
    Properties : {Address, BufferSize, NoFragmentation, PrimaryAddressResolutionStatus...}
    SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
    Qualifiers : {dynamic, provider}
    Site :
    Container :

    Example:

    get-adcomputer * -Property * | Select-Object name,dnshostname,operatingsystem,operatingsystemservicepack,ipv4address,lastlogondate,logoncount, @{label = "PingResults"; Expression = {Test-Connection $_.ipv4address | Select-Object ResponseTime}} |sort lastlogondate -Descending
    
  • #29214
    Profile photo of 37mm
    37mm
    Participant

    Ok, very cool. Thank you!

  • #29216
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    One last thing. Since you are wanting to save this to HTML, the ConvertTo-HTML cmdlet likes flat objects. With the previous commands, it will display great in PowerShell, but when piped into "ConvertTo-HTML | Out-File results.html", the "PingResults" column is blank. To give ConvertTo-HTML something it can deal with, you can loop through each of the ping results and just return the ResponseTime as a string rather than a collection of ResponseTime objects.

    get-adcomputer * -Property * | Select-Object name,dnshostname,operatingsystem,operatingsystemservicepack,ipv4address,lastlogondate,logoncount, @{label = "PingResults"; Expression = {Test-Connection $_.ipv4address | ForEach-Object {$_.ResponseTime}}} | sort lastlogondate -Descending | ConvertTo-Html | Out-File results.html
    
  • #29220
    Profile photo of 37mm
    37mm
    Participant

    The only problem I see with running the response time is it takes too long (knit picking I know) as opposed to running tnc -informationlevel quiet and just getting the true/false.

    Very cool, I am learning a bunch ! Your knowledge is very appreciated!

  • #29221
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Can you clarify TNC for me? I'm not familiar with that command.

  • #29222
    Profile photo of 37mm
    37mm
    Participant

    Test net connection? i though it was alias of test-connection?
    test-netconnection is what its an alias for

  • #29229
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Ah, I am running Windows 7 with PowerShell 4. I don't have Test-NetConnection. Thanks for the clarification.

You must be logged in to reply to this topic.