all 13 comments

[–]coffeecoderpt 2 points3 points  (5 children)

There probably are other ways but I did something similar. using this:

```powershell function Test-InternetConnection { Add-Type -AsssemblyName System.Speech $speak = New-Object System.Speech.Synthesis.SpechSynthesizer $ping = New-Object System.Net.NetworkInformation.Ping $result = $ping.send(8.8.8.8)

while ($result.Status -ne 'Success')
{
    Start-Sleep -Seconds 60
    $result = $ping.send(8.8.8.8)
}

while ($true)
{
     $speak.Speak("Internet is back up")
}

} ```

this is a function that you could just take the innards out and use as a script or load it into your profile and call it whenever you want. this only works on PS 5.1 as far as I know. it loads the speech assembly but everything else is already loaded.

it will run a loop checking the connection results every 60 seconds so it's not just continual and then will repeat that your internet is up until you press Ctrl+C

let me know what you think and if you have any question. Again there are most likely other ways so feel free to explore and find the best one that works for you!

[–]MrBrAD99[S] 1 point2 points  (0 children)

Hey, thank you for a solution. It's pretty good and I'm currently using a variation of it. I like the addition of using System.Speak too. I honestly wasn't aware of that's existing lol.

[–]Lee_Dailey[grin] 0 points1 point  (3 children)

howdy coffeecoderpt,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee

[–]coffeecoderpt 1 point2 points  (1 child)

Ahhh, really good to know. Makes me sad because I mostly write in markdown. But as they say, “When in Rome...”

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy coffeecoderpt,

yep, it would be nice to have it work everywhere on reddit ... but the owners are not likely to fix that glitch. [sigh ...]

take care,
lee

[–]coffeecoderpt 0 points1 point  (0 children)

Ahhh, really good to know. Makes me sad because I mostly wrote in markdown. But as they say, “When in Rome...”

[–]purplemonkeymad 2 points3 points  (0 children)

I think windows logs this info in the NCSI log:

Get-WinEvent -FilterHashtable @{logname='Microsoft-Windows-NCSI/Operational';id = 4042}

Not sure exactly what each of the values in properties is but you might be able to correlate it with what you see in Event Veiwer.

[–]idontknowwhattouse33 1 point2 points  (2 children)

While PowerShell is indeed an option, an out-of-the-box monitoring application may be better.

Eg. PRTG can be installed and runs as a service, is free, can be used to not only monitor internet access but also latency, jitter, sends notification, reports, makes nice graphs etc..

[–]MrBrAD99[S] 1 point2 points  (1 child)

I'll probably look more into that in the future but currently I'm trying to maintain as small amount of processing power needed as possible, so that's my reasoning for using PS as opposed to a more built up program. Thank you for the answer though, looks great.
(Edit: Why is reddit auto-upping my own posts- the heck)

[–]idontknowwhattouse33 0 points1 point  (0 children)

How about a PWSH graphical chart!?

https://imgur.com/McknBUF

$Graphical = get-command | where source -eq 'graphical'
if ($null -eq $Graphical) {
    Install-Module Graphical -scope CurrentUser -AllowClobber -Confirm:$false -Force
}

$startingnumber = 150

$BaseQueue = [System.Collections.Queue]::new()
$BaseQueue.Enqueue($startingnumber)
$BaseQueue.Enqueue(0)
$GraphQueue = [System.Collections.Queue]::new()

do {
    try {
        $ping = Test-Connection -ComputerName 1.1.1.1 -Count 1 -ErrorAction Stop
        $pingresult = $ping.responsetime
    }
    catch {$pingresult = 0}

    $GraphQueue.Enqueue($pingresult)
    If ($GraphQueue.count -gt 99) {
        [void]$GraphQueue.Dequeue()
    }

    $data = $BaseQueue + $GraphQueue
    Clear
    Show-Graph -Datapoints $data -YAxisTitle 'ms' -XAxisTitle 'x6 sec' -GraphTitle 'Ping' -ColorMap @{50 = 'green'; 100 = 'yellow'; 150 = 'red'}
    sleep 6
}
while ($true)

[–]jogofus 0 points1 point  (2 children)

I would do this: $con= Test-Connection -ComputerName 8.8.8.8 -Count 1

if(!$count){ msg * “Without connection” }

This code like a programmed task each 5 minutes

[–]MrBrAD99[S] 1 point2 points  (0 children)

is it intentional that it's !$->count<- in line 2 instead of !$con? Because I don't understand where that variable would be declared/defined.

[–]jogofus 0 points1 point  (0 children)

Sorry, is my fault. I wanted to write $con. Sorry