Last active
July 15, 2019 21:32
-
-
Save darrenjrobinson/2ab82c70d1d3335bbad2303c82fb19da to your computer and use it in GitHub Desktop.
Multi-Line Push Bullet Notification from PowerShell. Associated blogpost https://blog.darrenjrobinson.com/accessing-your-ubiquiti-unifi-network-configuration-with-powershell/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My Push Bullet Access Token | |
# Created via Profile Page https://www.pushbullet.com/#settings/account | |
$pbAccessToken = 'yourPushBulletAccessToken' | |
# Push Bullet API URI | |
$pbApiURI = "https://api.pushbullet.com/" | |
# Web Request Header | |
$pbHeader = @{"Access-Token" = $pbAccessToken | |
'Content-Type' = "application/json" | |
} | |
# Format for Push Notification | |
$pbBodyStatus = $null | |
foreach ($user in $uClientStatus) { | |
if ($user.homeSince) { | |
$pbBodyStatus += "$($user.hostname) $($user.status) \nLast Seen: $($user.lastHome) \nHome Since: $($user.homeSince) \n\n" | |
} | |
else { | |
$pbBodyStatus += "$($user.hostname) $($user.status) \nLast Seen: $($user.lastHome) \n\n" | |
} | |
} | |
$pbBody = @{"type" = "note" | |
"title" = "Who's Home and Away" | |
"body" = $pbBodyStatus | |
} | |
# Send Push Bullet Notification | |
try { | |
$pbNotification = Invoke-RestMethod -Method Post -Headers $pbHeader -Uri ($pbApiURI + "v2/pushes") -Body ($pbBody | convertto-json).Replace('\\n', '\n') | |
if ($pbNotification.active = $true) { | |
write-host -ForegroundColor Green "Push Bullet Notification successfully sent" | |
} | |
} | |
catch { | |
write-host -ForegroundColor Red "Push Bullet Notification Failed to Send" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment