Powershell Custom Push Notifications

I’m not sure if this will be useful to anyone else but I have found several requests for custom notifications and have wanted the same thing myself. I found a bash script (https://forums.sonarr.tv/t/custom-email-and-sms-notifications/14401) to do this but I run Sonarr on Windows and wanted to do it in Powershell so I didn’t have to install anything else. I use Pushbullet and wanted the notifications to show “Show name - S#:E##” instead of the default, this should be easy enough to customize for any other provider/format.

# Define Variables
$sonarr_episodefile_id = $env:sonarr_episodefile_id
$sonarr_series_id = $env:sonarr_series_id
$sonarr_series_title = $env:sonarr_series_title
$sonarr_episodefile_seasonnumber = $env:sonarr_episodefile_seasonnumber
$sonarr_episodefile_episodenumbers = $env:sonarr_episodefile_episodenumbers

$apikey="" # Your Sonarr API key 
$sonarr_address="http://localhost:8989" # Your Sonarr address (including base_url) 
$pushkey="" # Your PushBullet API key
$pushtag="" # Add the tag for your Pushbullet Channel or leave blank for direct push notifications

# Grab series information
$sonarr_series=$(Invoke-WebRequest -URI $sonarr_address/api/episode?seriesId=$sonarr_series_id -Header @{"X-Api-Key" = $apikey}) | ConvertFrom-Json

# Grab episode details
$sonarr_episode_title = $sonarr_series | where {$_.episodeFileId -eq $sonarr_episodefile_id} | Select -ExpandProperty title
$sonarr_episode_description = $sonarr_series | where {$_.episodeFileId -eq $sonarr_episodefile_id} | Select -ExpandProperty overview

# Format content
$pushtitle = $sonarr_series_title + " - S" + $sonarr_episodefile_seasonnumber + ":E" + $sonarr_episodefile_episodenumbers
$pushmessage = $sonarr_episode_title + " - " + $sonarr_episode_description

# Prepare push notification body
$pushbody = @{
    type = 'note'
    "title" = $pushtitle
    "body" = $pushmessage
    channel_tag = $pushtag

# Send push notification
Invoke-WebRequest -Method POST -Uri "https://api.pushbullet.com/v2/pushes" -Header @{"Access-Token" = $pushkey} -Body $pushBody

Complete the required fields (apikey, sonarr_address, pushkey and channel_tag) and save as CustomPush.ps1 in a safe location (I used C:\temp\CustomPush.ps1 in the example)

In Sonarr, go to Settings > Connect > + and create a “Custom Script” for “On Download” and “On Upgrade” and put the Path and Arguments as below:

Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -ExecutionPolicy ByPass -File C:\temp\CustomPush.ps1 (change this to suit your path)

This should now send you a push notification like this:

The Blacklist - S1:E23
The Freelancer - Liz and Red track an assassin who disguises his kills in large-scale catastrophes.

Now you know which show and episode has been downloaded instead of just getting “Sonarr - Episode Downloaded” in your notification.

Credit and thanks to bobbintb and his original notification script which I used to help create this.

Please note I have created bash scripts for both Sonarr and Radarr now. I have uploaded them and will be updating them in this GitHub repository: https://github.com/CJPCNZ/CustomPush

Can’t find any of those environmental variables on my win10 sonarr computer?
Do I have to enable something?


The variables are passed to the PowerShell script by Sonarr during the “On Download” trigger. They aren’t set globally on your PC so won’t be visible outside of Sonarr.