-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwifi_switch.ps1
More file actions
66 lines (48 loc) · 1.51 KB
/
Copy pathwifi_switch.ps1
File metadata and controls
66 lines (48 loc) · 1.51 KB
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
param([string]$mode)
$adapter = "WiFi"
function Wait-WifiUp {
do {
Start-Sleep 2
$state = (Get-NetAdapter -Name $adapter -ErrorAction SilentlyContinue).Status
} while ($state -ne "Up")
}
function Wait-WifiDown {
do {
Start-Sleep 2
$state = (Get-NetAdapter -Name $adapter -ErrorAction SilentlyContinue).Status
} while ($state -ne "Disabled")
}
Write-Host "`nWiFi Toggle Control System" -ForegroundColor Cyan
# ============================================
# OFF MODE
# ============================================
if ($mode -eq "off") {
Write-Host "Turning WiFi OFF..." -ForegroundColor Yellow
Disable-NetAdapter -Name $adapter -Confirm:$false
Start-Sleep 2
ipconfig /release
Write-Host "WiFi is OFF" -ForegroundColor Red
}
# ============================================
# ON MODE
# ============================================
elseif ($mode -eq "on") {
Write-Host "Turning WiFi ON..." -ForegroundColor Yellow
Enable-NetAdapter -Name $adapter -Confirm:$false
Wait-WifiUp
Start-Sleep 2
ipconfig /renew
Start-Sleep 3
Write-Host "`nTesting internet..." -ForegroundColor Cyan
Test-NetConnection 8.8.8.8
Test-NetConnection google.com
Write-Host "WiFi is ON" -ForegroundColor Green
}
# ============================================
# INVALID INPUT
# ============================================
else {
Write-Host "`nUsage:" -ForegroundColor Cyan
Write-Host ".\wifi_switch.ps1 on"
Write-Host ".\wifi_switch.ps1 off"
}