-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test-WlanNetConnection.ps1
119 lines (106 loc) · 4.05 KB
/
Test-WlanNetConnection.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<#PSScriptInfo
.VERSION 1.0.0
.DESCRIPTION Gets Wlan signal and packet loss details.
.AUTHOR Wojciech Ros ([email protected])
.COPYRIGHT Copyright (C) 2021 Wojciech Ros ([email protected])
.LICENSEURI http://www.apache.org/licenses/LICENSE-2.0
.GUID c05b391c-6e3e-4563-b079-92fa9bf491b0
#>
<#
.SYNOPSIS
Gets Wlan signal and packet loss details.
#>
[CmdletBinding()]
param (
# Specifies the number of tests. The default value is 4.
[int]$Count = 4,
# Specifies the interval between tests, in seconds.
[int]$Delay,
# Specifies the number of echo requests to send in each test. The default value is 4.
[int]$PingCount = 4
)
function Get-Timestamp {
return (Get-Date -Format "yyyy-MM-dd_HH-mm-ssK") -replace ':','-'
}
#TODO what if multiple interfaces?
function Get-NetshWlanInterfaceProperties {
param (
[string[]]$Properties = (
"Name",
"Description",
"GUID",
"Physical address",
"State",
"SSID",
"BSSID",
"Network type",
"Radio type",
"Authentication",
"Cipher",
"Connection mode",
"Channel",
"Receive rate (Mbps)",
"Transmit rate (Mbps)",
"Signal",
"Profile"
)
)
$NetshWlanInterfaceProperties = New-Object -TypeName PSObject
$NetshWlanShowInterfacesOutput = (netsh.exe wlan show interfaces) | Out-String
$Properties | ForEach-Object {
$NetshWlanShowInterfacesOutput -match "\b$_\b\s+:\s+(.*)" | Out-Null
$NetshWlanInterfaceProperties `
| Add-Member `
-MemberType NoteProperty `
-Name "$_" `
-Value $Matches[1]
}
return $NetshWlanInterfaceProperties
}
function Test-WlanNetConnection {
param (
# Specifies the number of tests. The default value is 4.
[int]$Count = 4,
# Specifies the interval between tests, in seconds.
[int]$Delay,
# Specifies the number of echo requests to send in each test. The default value is 4.
[int]$PingCount = 4
)
for ($i = 0; $i -lt $Count; $i++) {
$NetshWlanInterfaceProperties = Get-NetshWlanInterfaceProperties
$TestConnectionObject = Test-Connection `
-Count $PingCount `
-ComputerName `
"8.8.8.8", `
"1.1.1.1"
$TotalPingCount = $PingCount * 2
$TotalResponseTime = 0
$TestConnectionObject | ForEach-Object {
$TotalResponseTime += $_.ResponseTime
}
[int]$AverageResponseTime = ( $TotalResponseTime / $TestConnectionObject.Count )
$collection = [PSCustomObject]@{
Source = $TestConnectionObject[0].PSComputerName
Destination = $TestConnectionObject[0].Address
IPV4Address = $TestConnectionObject[0].IPV4Address
IPV6Address = $TestConnectionObject[0].IPV6Address
Bytes = $TestConnectionObject[0].Bytes
AverageResponseTime = $AverageResponseTime
PacketsSent = $TotalPingCount
PacketsReceived = $TestConnectionObject.Count
PacketsLost = ( $TotalPingCount - $TestConnectionObject.Count )
PacketLoss = ( 100% - ( $TestConnectionObject.Count / $TotalPingCount ) ).ToString("P")
WlanInterface = $NetshWlanInterfaceProperties.Description
SSID = $NetshWlanInterfaceProperties.SSID
BSSID = $NetshWlanInterfaceProperties.BSSID
Channel = $NetshWlanInterfaceProperties.Channel
Signal = $NetshWlanInterfaceProperties.Signal
}
$collection
Start-Sleep -Seconds $Delay
}
}
Test-WlanNetConnection `
-Count $Count `
-Delay $Delay `
-PingCount $PingCount