A need arose to determine the latency to a few different nodes and act on that matter. Someone on the internet had almost already written all the Powershell code I wanted. However the code was primarily focused on outputting the results in a CSV-file and not actually using the result in the best aus online casino code afterwards.
Therefore I have re-written this function to output an object instead.
##################################### ## Based on Ping-Latency ## Rewritten by Nicke Källén ## nicke dot kallen at applepie dot se ## Original header: ## http://kunaludapi.blogspot.com ## Version: 1 ## Tested this script on ## 1) Powershell v3 ## 2) Windows 7 ## ##################################### function Test-Latency { <# .SYNOPSIS Uses Test-Connection and determines latency to a host .DESCRIPTION Outputs each node with Hostname, IP-Address, Latency (ms) and Date .EXAMPLE Test-Latency -ComputerNames 192.168.0.1,google.com #> [CmdletBinding()] param( [Parameter(Mandatory=$False, ValueFromPipeline=$true, HelpMessage="Hostnames or IP-Address seperated by commas")] [alias("Computer")] [string[]]$ComputerNames = $env:COMPUTERNAME ) Begin {} Process { $ComputerNames = $ComputerNames.split(",") foreach ($Computer in $ComputerNames) { $Response = Test-Connection -ComputerName $computer -Count 1 -ErrorAction SilentlyContinue if ($Response -eq $null) { $object = New-Object –TypeName PSObject $object | Add-Member –MemberType NoteProperty –Name Hostname –Value $Computer $object | Add-Member –MemberType NoteProperty –Name IPaddress –Value "Unreachable" $object | Add-Member –MemberType NoteProperty –Name Latency –Value "No response" $object | Add-Member –MemberType NoteProperty –Name Date –Value $(Get-Date) $object } else { $object = New-Object –TypeName PSObject $object | Add-Member –MemberType NoteProperty –Name Hostname –Value $($Computer) $object | Add-Member –MemberType NoteProperty –Name IPAddress –Value $($Response.IPV4Address) $object | Add-Member –MemberType NoteProperty –Name Latency –Value $($Response.ResponseTime) $object | Add-Member –MemberType NoteProperty –Name Date –Value $(Get-Date) $object } } } End {} }