Guest User

Fix Tech Stuff Network TS

a guest
Sep 2nd, 2025
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. #This is a .PS1 script which can be run to test network issues. # Network Test Script
  2. # Purpose: Test why computer is not connecting to the intended Wi-Fi network
  3. # Output: networkreport.txt on Desktop with key test results
  4.  
  5.  
  6. #TO DIR NORMAL Get-ChildItem "$env:USERPROFILE\Desktop" -Force | Where-Object { $_.Name -like "*ocean*" }
  7.  
  8. #TO RUN
  9. #NORMAL RUN cd $env:USERPROFILE\Desktop
  10. #TO CHECK PATH [Environment]::GetFolderPath("Desktop")
  11.  
  12.  
  13. #CHECK IF USES ONE DRIVE [Environment]::GetFolderPath("Desktop")
  14.  
  15. # USES ONE DRIVE
  16. # CD NORMAL cd $env:USERPROFILE\Desktop
  17. # ONE DRIVE CD cd "$env:USERPROFILE\OneDrive\Desktop"
  18.  
  19.  
  20.  
  21. #POLICY
  22. #CHECK POLICY Get-ExecutionPolicy
  23. #RESTRICTED? Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
  24. #DONT FORGET TO UNDO
  25.  
  26.  
  27. #RUN FOR ONE DRIVE powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\OneDrive\Desktop\ocean.ps1"
  28. # ALT RUN FOR ONE DRIVE powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\OneDrive\Desktop\ocean.ps1"
  29.  
  30.  
  31. # Get Desktop path and report file
  32. $desktopPath = [Environment]::GetFolderPath("Desktop")
  33. $reportPath = Join-Path -Path $desktopPath -ChildPath "networkreport.txt"
  34.  
  35. # Function to log test results
  36. function Write-Log {
  37. param(
  38. [string]$Message,
  39. [string]$Severity = "INFO" # INFO, WARN, ERROR
  40. )
  41. $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
  42. $logMessage = "[$timestamp] [$Severity] $Message"
  43. Write-Host $logMessage -ForegroundColor $(if ($Severity -eq "ERROR") { "Red" } elseif ($Severity -eq "WARN") { "Yellow" } else { "White" })
  44. Add-Content -Path $reportPath -Value $logMessage
  45. }
  46.  
  47. # Clear previous report
  48. if (Test-Path $reportPath) { Clear-Content -Path $reportPath }
  49.  
  50. # Start report
  51. Write-Log "Network Test Report: Why Not Connecting to Intended Wi-Fi" -Severity "INFO"
  52. Write-Log "==================================================" -Severity "INFO"
  53.  
  54. # Test 1: Wi-Fi Adapter Status
  55. Write-Log "1. Wi-Fi Adapter Test" -Severity "INFO"
  56. $wifiAdapter = Get-NetAdapter | Where-Object { $_.InterfaceDescription -like "*Wireless*" -or $_.InterfaceDescription -like "*Wi-Fi*" }
  57. if ($wifiAdapter) {
  58. $adapterStatusSeverity = if ($wifiAdapter.Status -eq "Up") { "INFO" } else { "ERROR" }
  59. Write-Log "Wi-Fi Adapter: $($wifiAdapter.Name) is $($wifiAdapter.Status)" -Severity $adapterStatusSeverity
  60. if ($wifiAdapter.Status -eq "Disabled") { Write-Log "ERROR: Wi-Fi is disabled. Enable in Network Settings." -Severity "ERROR" }
  61. if ($wifiAdapter.MediaConnectionState -eq "Disconnected") { Write-Log "ERROR: Wi-Fi is disconnected. Check if turned on." -Severity "ERROR" }
  62. } else {
  63. Write-Log "ERROR: No Wi-Fi adapter found. Using Ethernet or hardware issue?" -Severity "ERROR"
  64. }
  65.  
  66. # Test 2: Current Wi-Fi Connection
  67. Write-Log "2. Current Wi-Fi Connection Test" -Severity "INFO"
  68. if ($wifiAdapter) {
  69. $wifiStatus = netsh wlan show interfaces | Select-String "SSID|State|Signal" | ForEach-Object { $_.Line.Trim() }
  70. if ($wifiStatus) {
  71. $ssid = ($wifiStatus | Where-Object { $_ -match "SSID" }) -replace ".*SSID\s+:\s+(.+)", '$1'
  72. $signal = ($wifiStatus | Where-Object { $_ -match "Signal" }) -replace ".*Signal\s+:\s+(\d+)%.*", '$1'
  73. $state = ($wifiStatus | Where-Object { $_ -match "State" }) -replace ".*State\s+:\s+(\w+).*", '$1'
  74. Write-Log "Connected SSID: $ssid" -Severity "INFO"
  75. $signalSeverity = if ([int]$signal -lt 50) { "WARN" } else { "INFO" }
  76. Write-Log "Signal Strength: $signal%" -Severity $signalSeverity
  77. $stateSeverity = if ($state -eq "connected") { "INFO" } else { "ERROR" }
  78. Write-Log "State: $state" -Severity $stateSeverity
  79. if ($state -ne "connected") { Write-Log "ERROR: Not connected to any Wi-Fi. Check credentials or range." -Severity "ERROR" }
  80. if ([int]$signal -lt 50) { Write-Log "WARN: Low signal may cause issues. Move closer to router." -Severity "WARN" }
  81. } else {
  82. Write-Log "ERROR: No Wi-Fi connection detected." -Severity "ERROR"
  83. }
  84. }
  85.  
  86. # Test 3: Available Wi-Fi Networks
  87. Write-Log "3. Available Wi-Fi Networks Test" -Severity "INFO"
  88. if ($wifiAdapter) {
  89. $networks = netsh wlan show networks | Select-String "SSID" | ForEach-Object { $_.Line -replace ".*SSID\s+\d+\s+:\s+(.+)", '$1' }
  90. if ($networks) {
  91. Write-Log "Visible Wi-Fi Networks:" -Severity "INFO"
  92. foreach ($network in $networks) { Write-Log " $network" -Severity "INFO" }
  93. Write-Log "Check if intended network is listed." -Severity "INFO"
  94. } else {
  95. Write-Log "ERROR: No Wi-Fi networks detected. Check adapter or location CHECK IF HAS ANTENNAS." -Severity "ERROR"
  96. }
  97. }
  98.  
  99. # Test 4: IP Configuration
  100. Write-Log "4. IP Configuration Test" -Severity "INFO"
  101. $ipConfig = Get-NetIPConfiguration | Where-Object { $_.InterfaceAlias -like "*Wi-Fi*" }
  102. if ($ipConfig) {
  103. $ip = $ipConfig.IPv4Address.IPAddress
  104. Write-Log "IP Address: $ip" -Severity "INFO"
  105. if ($ip -like "169.254.*.*") { Write-Log "ERROR: APIPA address detected. DHCP failure." -Severity "ERROR" }
  106. $gateway = $ipConfig.IPv4DefaultGateway.NextHop
  107. $gatewaySeverity = if ($gateway) { "INFO" } else { "ERROR" }
  108. Write-Log "Gateway: $gateway" -Severity $gatewaySeverity
  109. if (-not $gateway) { Write-Log "ERROR: No gateway. Cannot reach network." -Severity "ERROR" }
  110. } else {
  111. Write-Log "ERROR: No IP configuration for Wi-Fi. Check connection." -Severity "ERROR"
  112. }
  113.  
  114. # Test 5: Connectivity Tests
  115. Write-Log "5. Connectivity Tests" -Severity "INFO"
  116. if ($gateway) {
  117. Write-Log "Pinging Gateway ($gateway):" -Severity "INFO"
  118. $pingGateway = Test-Connection -ComputerName $gateway -Count 2 -ErrorAction SilentlyContinue
  119. if ($pingGateway) {
  120. $avgResponse = ($pingGateway | Measure-Object -Property ResponseTime -Average).Average
  121. Write-Log "Success (Avg: $avgResponse ms)" -Severity "INFO"
  122. } else {
  123. Write-Log "ERROR: Gateway ping failed. Check Wi-Fi or router." -Severity "ERROR"
  124. }
  125. }
  126. Write-Log "Pinging Google DNS (8.8.8.8):" -Severity "INFO"
  127. $pingInternet = Test-Connection -ComputerName "8.8.8.8" -Count 2 -ErrorAction SilentlyContinue
  128. if ($pingInternet) {
  129. $avgResponse = ($pingInternet | Measure-Object -Property ResponseTime -Average).Average
  130. Write-Log "Success (Avg: $avgResponse ms)" -Severity "INFO"
  131. } else {
  132. Write-Log "ERROR: No internet access. Check network or SSID." -Severity "ERROR"
  133. }
  134. Write-Log "DNS Resolution (google.com):" -Severity "INFO"
  135. try {
  136. $dns = Resolve-DnsName -Name "google.com" -ErrorAction Stop
  137. Write-Log "Success (IPs: $($dns.IPAddress -join ', '))" -Severity "INFO"
  138. } catch {
  139. Write-Log "ERROR: DNS failed. Check DNS settings." -Severity "ERROR"
  140. }
  141.  
  142. # Test 6: Known Wi-Fi Profiles
  143. Write-Log "6. Known Wi-Fi Profiles Test" -Severity "INFO"
  144. $profiles = netsh wlan show profiles | Select-String "All User Profile" | ForEach-Object { $_.Line -replace ".*:\s+(.+)", '$1' }
  145. if ($profiles) {
  146. Write-Log "Configured Profiles:" -Severity "INFO"
  147. foreach ($profile in $profiles) { Write-Log " $profile" -Severity "INFO" }
  148. } else {
  149. Write-Log "WARN: No Wi-Fi profiles found. Add intended network." -Severity "WARN"
  150. }
  151.  
  152. # Summary of Issues
  153. Write-Log "7. Summary of Issues" -Severity "INFO"
  154. $issues = @()
  155. if (-not $wifiAdapter) { $issues += "No Wi-Fi adapter detected." }
  156. if ($wifiAdapter -and $wifiAdapter.Status -ne "Up") { $issues += "Wi-Fi adapter is disabled or disconnected." }
  157. if ($wifiStatus -and $state -ne "connected") { $issues += "Not connected to any Wi-Fi network." }
  158. if ($wifiStatus -and $signal -and [int]$signal -lt 50) { $issues += "Low Wi-Fi signal ($signal%)." }
  159. if ($ipConfig -and $ip -like "169.254.*.*") { $issues += "APIPA address (DHCP failed)." }
  160. if ($ipConfig -and -not $gateway) { $issues += "No gateway configured." }
  161. if (-not $pingInternet) { $issues += "No internet access (failed ping to 8.8.8.8)." }
  162. if (-not (Resolve-DnsName -Name "google.com" -ErrorAction SilentlyContinue)) { $issues += "DNS resolution failed." }
  163. if ($issues) {
  164. foreach ($issue in $issues) { Write-Log "ISSUE: $issue Check related test results." -Severity "ERROR" }
  165. } else {
  166. Write-Log "No issues found. Verify intended SSID is in profiles and prioritized." -Severity "INFO"
  167. }
  168.  
  169. # End report
  170. Write-Log "==================================================" -Severity "INFO"
  171. Write-Log "Report saved to $reportPath" -Severity "INFO"
  172.  
  173. # Keep window open
  174. Write-Host "Press any key to exit..." -ForegroundColor Cyan
  175. $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Advertisement
Add Comment
Please, Sign In to add comment