forked from JohnDuprey/PSWindowsImageRepair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-Internet.ps1
48 lines (46 loc) · 1.47 KB
/
Test-Internet.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function Test-Internet {
<#
.SYNOPSIS
A simple function to grab the success rate of testing a destination's connection
.DESCRIPTION
A simple function to grab the success rate of testing a destination's connection and output as a consumable object.
.PARAMETER Destination
Destination you wish to test
.PARAMETER Count
Amount of times you want to test each destination
.INPUTS
Description of objects that can be piped to the script.
.OUTPUTS
Description of objects that are output by the script.
.EXAMPLE
Test-Internet -Destination "www.google.com"
.LINK
Links to further documentation.
.NOTES
Detail on what the script does, if this is needed.
#>
[CmdletBinding()]
param(
[parameter(Mandatory)]
[string[]]$Destination,
[parameter()]
[int]$Count = 5
)
begin {
$testConnectionParams = @{
Count = $Count
ErrorAction = 'SilentlyContinue'
}
}
process {
foreach ($dest in $Destination) {
$testConnectionParams.ComputerName = $dest
$successRate = Test-Connection @testConnectionParams
[PSCustomObject]@{
Destination = $dest
SuccessRate = [int]$("{0:N2}" -f (($successRate.count / $Count) * 100))
Count = $Count
}
}
}
}