Skip to main content

Hi Guys, I was tasked to develop a network health check due to a ton of our employees reporting network issues while WFH. Our theory was users we’re either using 10 year old modem/router combos or trying to work poolside outside their wifi range.



Evaluation: exit 0


We just run this script without eval codes on all machines, exiting 0 will make sure our devices are seen as “compliant”



So I broke this out into different functions, this all will report back into activity log, where you can export as CSV and do some excel number crunching on it







  1. Wifi strength, this will pull all wifi adapters and get their signal strength in a percentage. put it into the array $wifi and report back after 10 seconds







  2. Ping test, will ping 8.8.8.8 10 times and look for packet timeout/delay. Then we just cut the fat to save us some keystrokes in activity log







  3. Traceroute out to 8.8.8.8 again, but dont report back any routes that are less than 10ms in delay, again saving us on keystrokes in the activity log.







  4. Total uptime - pretty simple there, windows gets wonky after its been alive for too long, shows in days how long since reboot.







  5. Lastly, we check how much CPU usage and RAM usage over the course of 10 seconds, this’ll give us an idea if the user is maxing out their processor or running out of RAM.







Overall, this has helped our helpdesk team out by having some evidence that the issue may be on the users side, instead of just blaming IT. Feel free to let me know if theres a better way to accomplish this, or change values as desired.



Oh-- and lastly, it’ll Write in activity log with a delimiter of “~” so when you do your csv export, in Excel, break out your columns with the ~ as a delimiter.



Remediation:



###########################

#Script developed to get a basic understanding of a remote machine for helpdesk to look at and preemptively troubleshoot issues

#wifi signal test

$wifi = @()

For ($i=0; $i -le 5; $i++) {

$wifiloop =(netsh wlan show interfaces) -Match '^\s+Signal' -Replace '^\s+Signal\s+:\s+',''

$wifi += $wifiloop

Start-Sleep -s 2

}

###########################

#ping test to googles DNS, looking for packet drop and latency

$ping = Ping -n 10 8.8.8.8 | Select-String -Pattern 'Packets' -Context 0,3

$ping = $ping -replace ":", ""

$ping = $ping -replace "Approximate round trip times in milli-seconds", ""



###########################

#Trace route to googles DNS, looking for high latency at what hop

$trace = tracert 8.8.8.8 | Select-String -Pattern {\d{2,4} ms}

$tracert = if (!$trace) {echo "Trace: All under 10ms, OK"}

else {echo "Slow Trace Routes: $trace"}



###########################

#Total machine uptime over days

$uptime = (get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

$totaluptime = $uptime.TotalDays.ToString("#,0.00")

###########################

#Amount of free RAM available and CPU usage over 10 seconds

$totalRam = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).Sum

$a = 1

$RamCPU =

while($a -le 2)

{

$cpuTime = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue

$availMem = (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue

$availMem2 = ($availMem / 1048)

' AVG CPU: ' + $cpuTime.ToString("#,0.0") + '%, Avail. Mem.: ' + $availMem2.ToString("#,0.00") + 'GB (' + (104857600 * $availMem / $totalRam).ToString("#,0.0") + '%)'

$a++

Start-Sleep -s 5

}

###########################

#results writing to activity log

Write-Output "Days of Uptime: $totaluptime" '~'

Write-Output "Wifi signal over time: $wifi" '~'

Write-Output "$ping" '~'

Write-Output "$RamCPU" '~'

Write-Output "$tracert"

Hi Matt



I tried this worklet, but I’m not getting any results in the Activity log or Amagent log. I tried with the target device connected to company VPN and not connected. I pasted the exact remediation code from above.


Any idea where to start troubleshooting?


I found my error. Works great. Will come in handy.



Thanks


Mark


Reply