Pushover is a platform for sending and receiving push notifications to mobile devices (Android and iOS). Pushover is free, but requires the installation of a paid app on your Android or iOS device. After you set up your account on Pushover you get a user token that is used to identify you as the sender of a notification.
To send notifications, create a new application on the Pushover site. Give it a name, select type and upload an icon. After the application is registered you get an application token that identifies your application.
OK, so I wanted a notification sent to my phone whenever my computer restarted. Since it's a Windows 8 computer I decided to go for PowerShell 3.0 and created the following script:
$uri = "https://api.pushover.net/1/messages.json"Nothing special about the script, basically it's a slight modification of an example script found on the Pushover FAQ. Just replace <app token> and <user token> with your own tokens.
$parameters = @{
token = "<app token>"
user = "<user token>"
title = "Reboot"
message = "Your computer just rebooted"
}
$parameters | Invoke-RestMethod -Uri $uri -Method Post
Next, I need to have the script run when the computer starts, and run before anyone logs on. That's the point, right, if I'm at the computer I don't need a notification telling me the computer restarted.
Run the Local Group Policy Editor (gpedit.msc) tool as administrator and drill down to Local Computer Policy -> Computer Configuration -> Windows Settings -> Scripts and open Startup.
All done!
This is exactly what I'm seeking. BUT I cannot get it to Run in PowerShell 2.0 (Win764Bit PC.)
ReplyDeleteError below: The term 'Invoke-RestMethod' is not recognized as the na
ck the spelling of the name, or if a path was included,
At C:\Users\GServer\Documents\Scripts\PushReboot.ps1:8 c
+ $parameters | Invoke-RestMethod <<<< -uri $uri -Metho
+ CategoryInfo : ObjectNotFound: (Invoke-Re
+ FullyQualifiedErrorId : CommandNotFoundException
Can anyone please help to get this working in Powershell 2 - I've even tried upgrading to Powershell 3, but that just hangs at Initialising Install.