-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHotSpotManager.ps1
33 lines (25 loc) · 1.62 KB
/
HotSpotManager.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
$connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
$tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)
$StartupTimestamp = Get-Date #* Remember the time, when program started
while($true){
#* Check Mobile Hotspot state and test internet connection
if (($tetheringManager.TetheringOperationalState -eq 'InTransition') -or !(Test-Connection internetbeacon.msedge.net -Quiet)){
#? You can delete TestConnection sentence, if you don't need it, because it will reboot your pc
#! Rebooting PC, because Hotspot may stuck in 'InTransition' state :(
Write-Output -Verbose "I will reboot your PC in a few seconds, because Mobile Hotspot is bugging. Kill this window to stop it :)"
Start-Sleep -Seconds 7
Restart-Computer -Force
}
elseif($tetheringManager.TetheringOperationalState -eq 'Off'){
#* Start Mobile Hotspot
$tetheringManager.StartTetheringAsync()
Write-Output -Verbose "$(Get-Date) --- Wifi set to On | Startup Time - $StartupTimestamp"
Start-Sleep -Seconds 600
}
elseif($tetheringManager.TetheringOperationalState -eq 'On'){
#* Stop Mobile Hotspot
$tetheringManager.StopTetheringAsync()
Write-Output -Verbose "$(Get-Date) --- Wifi set to Off | Startup Time - $StartupTimestamp"
Start-Sleep -Seconds 7
}
}