How do I connect to the same wireless network ssid with different username and credentials with a script on my windows pc?

Pietro Guzzetti 0 Reputation points
2025-01-31T12:18:54.74+00:00

I need to test the connection to a unique wifi SID using credentials different (a list of username and password; once authenticated i need to ping a google dns in order to verify that internet can be reached for any connection established with different account

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
12,064 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,385 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,747 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,811 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. guilherme rodrigues 390 Reputation points
    2025-02-12T15:06:02.1333333+00:00

    Hi @Pietro Guzzetti !

    I tested the following script, and it ran successfully. I hope it works for you.

    You will need to create a .csv file with the following information:

    users,passwords

    user1,password123

    user2,password456

    Make sure to modify the first two variables, which are the Wi-Fi network name and the path to the CSV file.

    # Change here

    $SSID = "YourWiFiNetwork" # Target Wi-Fi network name

    $CSVPath = "C:\path\to\credentials.csv" # Path to the CSV file with credentials

    $PingAddress = "8.8.8.8" # Google's DNS for connectivity test

    $Credentials = Import-Csv -Path $CSVPath

    foreach ($cred in $Credentials) {

    $Username = $cred.Username

    $Password = $cred.Password

    Write-Host "`nTesting connection with username: $Username..." -ForegroundColor Yellow

    # Connect to Wi-Fi using the provided credentials

    $ConnectCommand = "netsh wlan connect name=$SSID user=$Username password=$Password"

    Invoke-Expression $ConnectCommand

    Start-Sleep -Seconds 5

    $PingResult = Test-Connection -ComputerName $PingAddress -Count 2 -Quiet

    if ($PingResult) {

    Write-Host "Successfully connected using $Username! Internet is accessible." -ForegroundColor Green

    } else {

    Write-Host "Connection failed or no Internet access." -ForegroundColor Red

    }

    Write-Host "Disconnecting..." -ForegroundColor Yellow

    netsh wlan disconnect

    Start-Sleep -Seconds 3

    }

    Write-Host "`nTesting completed!" -ForegroundColor Cyan

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.