Great Pushover PowerShell Cmdlet for alerts

I wanted to share this awesome project I came across on Reddit. As you may know, Send-MailMessage in PowerShell is deprecated and there doesn’t seem to be a replacement. Some of the scripts floating around have that built in for alerting but it’s wonky and if you’re using Gmail you’ll have to allow "less secure " app logins.

For my use case, Poshover completely replaces the need for Send-MailMessage.

Here’s the PowerShell switch I added to what I’ll be running regularly which uses the exit code from restic:

        switch ($LASTEXITCODE) {
            0 { 
                Send-Pushover -Message "Backup for $($path.Name) finished with no errors. $($duration.Hours) hours $($duration.Minutes) minutes." 
                Write-Host "Backup for $($path.Name) finished with no errors. $($duration.Hours) hours $($duration.Minutes) minutes"
            }
            1 {
                Send-Pushover -Message "Backup for $($path.Name) failed with fatal error. No backup was made." -MessagePriority High
                Write-Host "Backup for $($path.Name) failed with fatal error. No backup was made."
            }
            3 {
                Send-Pushover -Message "Backup for $($path.Name) finished with some errors. $($duration.Hours) hours $($duration.Minutes) minutes"
                Write-Host "Backup for $($path.Name) finished with some errors. $($duration.Hours) hours $($duration.Minutes) minutes"
            }
        }

This assumes that you’ve used the Set-PushoverConfig -Token $token -User $user option.

I’m even thinking about parsing the log to include things like how much data was added to the repo and passing that to Pushover as well.

Thought you all might find that useful.

I also stole the restic image from the documentation site for the Pushover image so the alerts look like this:

2 Likes

https://ntfy.sh/ similar project to PuhOver

1 Like

Some of the scripts floating around have that built in for alerting but it’s wonky and if you’re using Gmail you’ll have to allow "less secure " app logins.

But you can still use a silly email address to send messages, even to a Gmail box. Right?

Blockquote

With Poshover you can also send the summary of added files, new ones, etc…?

Thanks for the information, but it is much more expensive than Pushover