Function Test-MultipleConnections { param ( [string]$Gateway, [int]$StartPosition = 1, [int]$EndPosition = 255 ) if ($Gateway -match "(\d{1,3}\.){2}\d{1,3}") { $StartPosition..$EndPosition | Foreach-Object { $ResultHash = @{} $ResultHash.Address = "{0}.{1}" -f $Matches[0], $_ $ResultHash.IsSuccess = Test-Connection $ResultHash.Address -count 1 -quiet New-Object PSObject -Property $ResultHash } } }