Run a ping and display results in table

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!

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

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 ?

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?

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

Ok, very cool. Thank you!

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

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!

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

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

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