Skip to content

Instantly share code, notes, and snippets.

@imorrish
Last active Sep 22, 2016
Embed
What would you like to do?
PowerShell function to send alert to PushAlot
function Send-PushAlot {
<#
.SYNOPSIS
Send alert via https://pushalot.com/api#webapi to Windows Phone or Desktop device app
#>
Param(
[String]
[parameter(Mandatory=$true)]
[ValidateLength(1,250)]
$pushTitle = "test",
[String]
[parameter(Mandatory=$true)]
[ValidateLength(1,32768)]
$pushBody = "text here",
[String]
[ValidateLength(1,100)]
$pushLinkTitle = 'Gist GitHub Link',
[String]
[ValidateLength(1,1000)]
$pushLink = 'https://gist.github.com/imorrish/ae0b20327b9b9d63d94d',
[String]
$pushURI = 'https://pushalot.com/api/sendmessage',
[String]
$pushToken = 'Put your token from https://pushalot.com here'
)
BEGIN{
Add-Type -AssemblyName System.Web
}
PROCESS{
try
{
$message = Invoke-WebRequest -Uri $pushURI -Method POST -Body "AuthorizationToken=$($pushToken)&Title=$([System.Web.HttpUtility]::UrlEncode($pushTitle))&Body=$([System.Web.HttpUtility]::UrlEncode($pushBody))&LinkTitle=$([System.Web.HttpUtility]::UrlEncode($pushLinkTitle))&Link=$([System.Web.HttpUtility]::UrlEncode($pushLink))"
switch ($message.StatusCode)
{
"200" {Write-Host -ForegroundColor Green "Message Sent"}
"400" {Write-Host -ForegroundColor Red "Input data validation failed. Check result information Description field for detailed information."}
"406" {Write-Host -ForegroundColor Red "Message throttle limit hit. Check result information Description field for information which limit was exceeded."}
"410" {Write-Host -ForegroundColor Red "The AuthorizationToken is no longer valid and no more messages should be ever sent again using that token. "}
"500" {Write-Host -ForegroundColor Red "Something is broken"}
"510" {Write-Host -ForegroundColor Red "servers are currently overloaded with requests"}
}
}
catch [System.Net.WebException]
{
Write-Host -ForegroundColor Red $_.Exception.Message
}
finally
{
}
}
END{}
}
@shareonline
Copy link

shareonline commented Sep 22, 2016

Nice! Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment