Skip to content

Instantly share code, notes, and snippets.

@imorrish
Last active September 22, 2016 06:50
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 imorrish/ae0b20327b9b9d63d94d to your computer and use it in GitHub Desktop.
Save imorrish/ae0b20327b9b9d63d94d to your computer and use it in GitHub Desktop.
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

Nice! Thanks 👍

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