File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-PingResultsHashTable {
2+ [CmdletBinding ()]
3+ param (
4+ # A server name or array of server names
5+ [Parameter (Mandatory )]
6+ [string []]
7+ $ServerList
8+ )
9+
10+ # Build an ordered hash table that has the server name as the key and the IP address [and any errors] as the value.
11+ $Servers = [ordered ]@ {}
12+ $ServerList | ForEach-Object {
13+ $Results = Test-NetConnection $_ - InformationLevel Detailed
14+ if ($Results.PingSucceeded ) {
15+ $Servers.Add ( $Results.ComputerName , $ ($Results.ResolvedAddresses.Where (
16+ { $_.AddressFamily -eq ' InterNetwork' }).IPAddressToString) )
17+ } else {
18+ $Servers.Add ( $Results.ComputerName , " $ ( $Results.ResolvedAddresses.Where (
19+ {$_.AddressFamily -eq ' InterNetwork' }).IPAddressToString) : $ ( $Error [0 ].Exception.Message) " )
20+ }
21+ }
22+ $Servers
23+ }
You can’t perform that action at this time.
0 commit comments