Created
October 22, 2025 12:00
-
-
Save tuxitop/2ee124d3f0d2e2c9bdc0c4fb560498bc to your computer and use it in GitHub Desktop.
Automate kerio login in windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Author: Ali Mousavi | |
| ## Last Updated: 2025-10-22 | |
| ## Description: This script checks the SSID of the Wifi network and | |
| ## if it matches, trys to log in with kerio. | |
| ## Hint: Further automation can be made using windows task scheduler. | |
| ## e.g. run the script on network change. | |
| $Ssid = '' # SSID of the wifi | |
| $KerioURL = '' # https://kerio.example.com | |
| $KerioUser = '' | |
| $KerioPass = '' | |
| function Get-CurrentWifiSsid { | |
| # Uses netsh (works on most Windows versions) | |
| $out = netsh wlan show interfaces 2>$null | |
| if (-not $out) { | |
| return $null | |
| } | |
| foreach ($line in $out) { | |
| if ($line -match '^\s*SSID\s*:\s*(.+)$') { | |
| return $matches[1].Trim() | |
| } | |
| } | |
| return $null | |
| } | |
| function LoginKerio { | |
| $requestParams = @{ | |
| Uri = "$KerioURL/internal/dologin.php" | |
| Method = 'POST' | |
| Body = @{ | |
| "kerio_username" = $KerioUser | |
| "kerio_password" = $KerioPass | |
| } | |
| ContentType = "application/x-www-form-urlencoded" | |
| } | |
| try { | |
| # Using Invoke-RestMethod for JSON/text response handling | |
| $response = Invoke-WebRequest @requestParams | |
| Write-Host "✅ Request Sent." | |
| if ($respose.Content -like "*The following user is currently logged on from your computer*") { | |
| Write-Host "⚠️ Someone is currently logged in. Nothing to do." | |
| exit 0 | |
| } elseif ($response.Content -like "*Incorrect username or password*") { | |
| Write-Host "❌ Login failed. Invalid username or password." | |
| exit 2 | |
| } else { | |
| Write-Host "✅ Logged in successfully." | |
| } | |
| } | |
| catch { | |
| Write-Host "❌ Request failed:" | |
| Write-Host $_.Exception.Message | |
| } | |
| } | |
| $currentSsid = Get-CurrentWifiSsid | |
| if ($null -eq $currentSsid) { | |
| Write-Host "Not connected to any Wi-Fi network." | |
| exit 1 | |
| } | |
| if ($currentSsid -ieq $Ssid) { | |
| Write-Host "✅ Connected to '$Ssid' — Logging in with kerio" | |
| LoginKerio | |
| } else { | |
| Write-Host "⚠️ SSID('$currentSsid') does not match '$Ssid'. Nothing to do." | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To automate running the script using windows task scheduler:
🔒 General Tab:
Select a name⏰ Triggers Tab:
⚙️ Actions Tab:
Conditions Tab: