Partager via


Windows Phone Push Notifications for your OpsMgr Alerts - Part 1

Did you know you can easily create your own Windows Phone Push Notifications using the Notify My Windows Phone app?

NMWP is a platform that helps you push information to virtually any Windows Phone 7 (and 8) device you own.

What do you need to get started?

  1. Windows Phone 7 or 8
  2. The NMWP app from the Microsoft Store ($1.99)
  3. NMWP Api key
  4. PowerShell script to call the Web API

 

First we need to install the The NMWP app from the Microsoft Store on our Windows Phone. Open the Windows Store app on your Windows Phone and install the app.

nmwp7

Next we need to Sign up at https://www.nmwp7.com/user/register and create a username and password.

image

 

After registering you need to enter your username and password at the Notify my Windows Phone app on your Windows Phone.

nmwp7_2

And at last we need to request an API key on the https://www.nmwp7.com/user/apikeys website.

image

 

After requesting the API key you can test the key using the Send testmessage button.

image

Hopefully now everything is working as expected.

Testing Notify My Windows Phone from PowerShell

If you look at the API help it’s pretty simple to call the API. With PowerShell v3 you can use the Invoke-WebRequest cmdlet to call the Web API.

A simple PowerShell script to call the Web API can look something like this:

 #Requires -Version 3

#######################################################################################################################                        
# Using the Notify my Windows Phone API using PowerShell                        
# Author: Stefan Stranger            
# Disclamer: This program source code is provided "AS IS" without warranty representation or condition of any kind
#            either express or implied, including but not limited to conditions or other terms of merchantability and/or
#            fitness for a particular purpose. The user assumes the entire risk as to the accuracy and the use of this
#            program code.
# Date:        01-05-2012                       
# Name:     NotifyMyWindowPhone.ps1            
# v0.01 -     01-05-2012 - Stefan Stranger - sstranger's initial release               
########################################################################################################################

# Enter your own API Key from https://www.nmwp7.com/user/apikeys
$apikey = "[enter here your api key]"

# Enter the name of the application the notification originates from. 
$application = "WindowsPowerShell"

# Enter The event that occured. Depending on your application, this might be a summary, subject or a brief explanation.
$event = "Push Message sent from PowerShell"

# The full body of the notification. 
$description = "This message was sent as a test"

# An optional value representing the priority of the notification.
$priority = "-2"

# Specifies the responsetype you want. You can currently choose between JSON or XML (default)
$type = "json"

$uri = "https://notifymywindowsphone.com/publicapi/notify?event=$event&priority=$priority&application=$application&description=$description&apikey=$apikey&type=$type"

Invoke-WebRequest -Uri $uri

If you run above PowerShell script you will see the following result returned in your console.

image

Now you would see the push notification on your Windows Phone.

nmwp7_3

In my next blog post I’ll explain how you can use above to create Windows Phone Push Notifications for your OpsMgr Alerts using the Notification Command Channel.

Have fun!

Comments