Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This is a .PS1 script which can be run to test network issues. # Network Test Script
- # Purpose: Test why computer is not connecting to the intended Wi-Fi network
- # Output: networkreport.txt on Desktop with key test results
- #TO DIR NORMAL Get-ChildItem "$env:USERPROFILE\Desktop" -Force | Where-Object { $_.Name -like "*ocean*" }
- #TO RUN
- #NORMAL RUN cd $env:USERPROFILE\Desktop
- #TO CHECK PATH [Environment]::GetFolderPath("Desktop")
- #CHECK IF USES ONE DRIVE [Environment]::GetFolderPath("Desktop")
- # USES ONE DRIVE
- # CD NORMAL cd $env:USERPROFILE\Desktop
- # ONE DRIVE CD cd "$env:USERPROFILE\OneDrive\Desktop"
- #POLICY
- #CHECK POLICY Get-ExecutionPolicy
- #RESTRICTED? Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
- #DONT FORGET TO UNDO
- #RUN FOR ONE DRIVE powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\OneDrive\Desktop\ocean.ps1"
- # ALT RUN FOR ONE DRIVE powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\OneDrive\Desktop\ocean.ps1"
- # Get Desktop path and report file
- $desktopPath = [Environment]::GetFolderPath("Desktop")
- $reportPath = Join-Path -Path $desktopPath -ChildPath "networkreport.txt"
- # Function to log test results
- function Write-Log {
- param(
- [string]$Message,
- [string]$Severity = "INFO" # INFO, WARN, ERROR
- )
- $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
- $logMessage = "[$timestamp] [$Severity] $Message"
- Write-Host $logMessage -ForegroundColor $(if ($Severity -eq "ERROR") { "Red" } elseif ($Severity -eq "WARN") { "Yellow" } else { "White" })
- Add-Content -Path $reportPath -Value $logMessage
- }
- # Clear previous report
- if (Test-Path $reportPath) { Clear-Content -Path $reportPath }
- # Start report
- Write-Log "Network Test Report: Why Not Connecting to Intended Wi-Fi" -Severity "INFO"
- Write-Log "==================================================" -Severity "INFO"
- # Test 1: Wi-Fi Adapter Status
- Write-Log "1. Wi-Fi Adapter Test" -Severity "INFO"
- $wifiAdapter = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "*Wireless*" -or $_.InterfaceDescription -like "*Wi-Fi*" }
- if ($wifiAdapter) {
- $adapterStatusSeverity = if ($wifiAdapter.Status -eq "Up") { "INFO" } else { "ERROR" }
- Write-Log "Wi-Fi Adapter: $($wifiAdapter.Name) is $($wifiAdapter.Status)" -Severity $adapterStatusSeverity
- if ($wifiAdapter.Status -eq "Disabled") { Write-Log "ERROR: Wi-Fi is disabled. Enable in Network Settings." -Severity "ERROR" }
- if ($wifiAdapter.MediaConnectionState -eq "Disconnected") { Write-Log "ERROR: Wi-Fi is disconnected. Check if turned on." -Severity "ERROR" }
- } else {
- Write-Log "ERROR: No Wi-Fi adapter found. Using Ethernet or hardware issue?" -Severity "ERROR"
- }
- # Test 2: Current Wi-Fi Connection
- Write-Log "2. Current Wi-Fi Connection Test" -Severity "INFO"
- if ($wifiAdapter) {
- $wifiStatus = netsh wlan show interfaces | Select-String "SSID|State|Signal" | ForEach-Object { $_.Line.Trim() }
- if ($wifiStatus) {
- $ssid = ($wifiStatus | Where-Object { $_ -match "SSID" }) -replace ".*SSID\s+:\s+(.+)", '$1'
- $signal = ($wifiStatus | Where-Object { $_ -match "Signal" }) -replace ".*Signal\s+:\s+(\d+)%.*", '$1'
- $state = ($wifiStatus | Where-Object { $_ -match "State" }) -replace ".*State\s+:\s+(\w+).*", '$1'
- Write-Log "Connected SSID: $ssid" -Severity "INFO"
- $signalSeverity = if ([int]$signal -lt 50) { "WARN" } else { "INFO" }
- Write-Log "Signal Strength: $signal%" -Severity $signalSeverity
- $stateSeverity = if ($state -eq "connected") { "INFO" } else { "ERROR" }
- Write-Log "State: $state" -Severity $stateSeverity
- if ($state -ne "connected") { Write-Log "ERROR: Not connected to any Wi-Fi. Check credentials or range." -Severity "ERROR" }
- if ([int]$signal -lt 50) { Write-Log "WARN: Low signal may cause issues. Move closer to router." -Severity "WARN" }
- } else {
- Write-Log "ERROR: No Wi-Fi connection detected." -Severity "ERROR"
- }
- }
- # Test 3: Available Wi-Fi Networks
- Write-Log "3. Available Wi-Fi Networks Test" -Severity "INFO"
- if ($wifiAdapter) {
- $networks = netsh wlan show networks | Select-String "SSID" | ForEach-Object { $_.Line -replace ".*SSID\s+\d+\s+:\s+(.+)", '$1' }
- if ($networks) {
- Write-Log "Visible Wi-Fi Networks:" -Severity "INFO"
- foreach ($network in $networks) { Write-Log " $network" -Severity "INFO" }
- Write-Log "Check if intended network is listed." -Severity "INFO"
- } else {
- Write-Log "ERROR: No Wi-Fi networks detected. Check adapter or location CHECK IF HAS ANTENNAS." -Severity "ERROR"
- }
- }
- # Test 4: IP Configuration
- Write-Log "4. IP Configuration Test" -Severity "INFO"
- $ipConfig = Get-NetIPConfiguration | Where-Object { $_.InterfaceAlias -like "*Wi-Fi*" }
- if ($ipConfig) {
- $ip = $ipConfig.IPv4Address.IPAddress
- Write-Log "IP Address: $ip" -Severity "INFO"
- if ($ip -like "169.254.*.*") { Write-Log "ERROR: APIPA address detected. DHCP failure." -Severity "ERROR" }
- $gateway = $ipConfig.IPv4DefaultGateway.NextHop
- $gatewaySeverity = if ($gateway) { "INFO" } else { "ERROR" }
- Write-Log "Gateway: $gateway" -Severity $gatewaySeverity
- if (-not $gateway) { Write-Log "ERROR: No gateway. Cannot reach network." -Severity "ERROR" }
- } else {
- Write-Log "ERROR: No IP configuration for Wi-Fi. Check connection." -Severity "ERROR"
- }
- # Test 5: Connectivity Tests
- Write-Log "5. Connectivity Tests" -Severity "INFO"
- if ($gateway) {
- Write-Log "Pinging Gateway ($gateway):" -Severity "INFO"
- $pingGateway = Test-Connection -ComputerName $gateway -Count 2 -ErrorAction SilentlyContinue
- if ($pingGateway) {
- $avgResponse = ($pingGateway | Measure-Object -Property ResponseTime -Average).Average
- Write-Log "Success (Avg: $avgResponse ms)" -Severity "INFO"
- } else {
- Write-Log "ERROR: Gateway ping failed. Check Wi-Fi or router." -Severity "ERROR"
- }
- }
- Write-Log "Pinging Google DNS (8.8.8.8):" -Severity "INFO"
- $pingInternet = Test-Connection -ComputerName "8.8.8.8" -Count 2 -ErrorAction SilentlyContinue
- if ($pingInternet) {
- $avgResponse = ($pingInternet | Measure-Object -Property ResponseTime -Average).Average
- Write-Log "Success (Avg: $avgResponse ms)" -Severity "INFO"
- } else {
- Write-Log "ERROR: No internet access. Check network or SSID." -Severity "ERROR"
- }
- Write-Log "DNS Resolution (google.com):" -Severity "INFO"
- try {
- $dns = Resolve-DnsName -Name "google.com" -ErrorAction Stop
- Write-Log "Success (IPs: $($dns.IPAddress -join ', '))" -Severity "INFO"
- } catch {
- Write-Log "ERROR: DNS failed. Check DNS settings." -Severity "ERROR"
- }
- # Test 6: Known Wi-Fi Profiles
- Write-Log "6. Known Wi-Fi Profiles Test" -Severity "INFO"
- $profiles = netsh wlan show profiles | Select-String "All User Profile" | ForEach-Object { $_.Line -replace ".*:\s+(.+)", '$1' }
- if ($profiles) {
- Write-Log "Configured Profiles:" -Severity "INFO"
- foreach ($profile in $profiles) { Write-Log " $profile" -Severity "INFO" }
- } else {
- Write-Log "WARN: No Wi-Fi profiles found. Add intended network." -Severity "WARN"
- }
- # Summary of Issues
- Write-Log "7. Summary of Issues" -Severity "INFO"
- $issues = @()
- if (-not $wifiAdapter) { $issues += "No Wi-Fi adapter detected." }
- if ($wifiAdapter -and $wifiAdapter.Status -ne "Up") { $issues += "Wi-Fi adapter is disabled or disconnected." }
- if ($wifiStatus -and $state -ne "connected") { $issues += "Not connected to any Wi-Fi network." }
- if ($wifiStatus -and $signal -and [int]$signal -lt 50) { $issues += "Low Wi-Fi signal ($signal%)." }
- if ($ipConfig -and $ip -like "169.254.*.*") { $issues += "APIPA address (DHCP failed)." }
- if ($ipConfig -and -not $gateway) { $issues += "No gateway configured." }
- if (-not $pingInternet) { $issues += "No internet access (failed ping to 8.8.8.8)." }
- if (-not (Resolve-DnsName -Name "google.com" -ErrorAction SilentlyContinue)) { $issues += "DNS resolution failed." }
- if ($issues) {
- foreach ($issue in $issues) { Write-Log "ISSUE: $issue Check related test results." -Severity "ERROR" }
- } else {
- Write-Log "No issues found. Verify intended SSID is in profiles and prioritized." -Severity "INFO"
- }
- # End report
- Write-Log "==================================================" -Severity "INFO"
- Write-Log "Report saved to $reportPath" -Severity "INFO"
- # Keep window open
- Write-Host "Press any key to exit..." -ForegroundColor Cyan
- $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Advertisement
Add Comment
Please, Sign In to add comment