Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active July 15, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/2ab82c70d1d3335bbad2303c82fb19da to your computer and use it in GitHub Desktop.
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/
# 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