Quick Powershell Script for Plex/Grafana

Here’s a quick example script for pushing data from a web API with powershell, into a InfluxDB Database. Replace “TOKEN” with your Plex token.

while ($true)
#clean previous connection
$ServicePoint = [System.Net.ServicePointManager]::FindServicePoint("")
#you could do something like this or manually clear out as required.
$ServicePoint.ConnectionLimit = 10
#start clean
# Server URL of PlexPY API to request from
$request = "http://slimleech.local:32400/status/sessions/?X-Plex-Token=TOKEN"
#Grab the data and count it
$object = Invoke-WebRequest $request | select content
$result = $object | select-string -allmatches -Pattern 'Player' | Select-Object -ExpandProperty Matches
$final = $result.count
#Push the data to influxdb
$uri = ''
$postParams = "plex_users,host=slimleech value=$final"
Invoke-RestMethod -Uri $uri -Method POST -Body $postParams
Write-Host "Number of People watching is $final"
start-sleep 60
Share this content:

Leave a Comment

Your email address will not be published. Required fields are marked *