MSEndpointMgr

ConfigMgr OSD Notification Service – Pushover

Notification Service

Over the past few months I have seen people create systems to monitor OSD deployments, for example Damien Van Robaeys has a really nice one for MDT (Monitor MDT Deployments) most use email for delivery. I have been using a service called pushover for years for various services like Plex, GitHub, IFTTT, Nagios and now for OSD.

What we all want is a simple system to notify us when for example an OSD Deployment has Completed Successfully or has Failed when we are out and about/on the toilet šŸ™‚ .

What we need is a way to show support and management what’s worked and what hasn’t, one single pane of glass for everyone. In the next month I will need to re-image over 2K workstations but when I automatically image machines I needed a way for all concerned to monitor the imaging and respond to any failures quickly.

I have tried to keep this post pretty basic as i’m not 100% sure how interested people will be.

What is Pushover

Pushover uses a simple, versioned REST API to receive messages and broadcast them to devices running the device clients. To simplify the user registration process and usage of the API, there are no complicated out-of-band authentication mechanisms or per-call signing libraries required, such as OAuth. Standard HTTP libraries available in just about every language, or even from the command line, can be used without any custom modules or extra dependencies needed. See the FAQ

In essence Pushover uses an app on Android/iOS/Chrome to display a notification

Setting up an account

Once you register at https://pushover.net you will be given a User Key to use with the API and an Email you can use to send messages to Pushover.

Note: I’m currently using the free client for home but for my work environment I’m looking at the paid for service.

Once that’s done you can register a device for example my work phone (Samsung Galaxy S7)

Creating an Application

In this example I’m going to create a SCConfigMgr Application in PushOver and then using my Powershell script below send messages to all my devices.

  1. Once logged in scroll down to “Create an Application/API Token”
  2. Fill in the details Name/Type/Icon etc.
  3. Once completed you now have an Application API Token to use.

Putting it together

Once your account is set up and you have created an application API you can now do one of two things, create a basic message on the site or use the API and powershell.

Basic Message

You can send a basic message from the website to all your devices (or individual ones) or groups.

Basic Powershell Example

$uri = "https://api.pushover.net/1/messages.json"
$parameters = @{
  token = "APP_TOKEN"
  user = "USER_KEY"
  message = "hello world"
}
$parameters | Invoke-RestMethod -Uri $uri -Method Post

Advanced Powershell Example

This is the one I’m testing in my own environment, I have it as part of the main OSD task sequence but Powershell and Pushover can be used via Status Messages in ConfigMgr or trigger by an event, it’s very flexible, its really up to you.

Scripting a message

Use the API and powershell to send a message (below is from the Pushover site and gives you a rough idea of how it works).

  1. Register your application, set its name and upload an icon, and get an API token in return (often referred to as APP_TOKEN in our documentation and code examples).
  2. POST an HTTPS request to https://api.pushover.net/1/messages.json with the following parameters:
    • token (required) – your application’s API token
    • user (required) – the user/group key (not e-mail address) of your user (or you), viewable when logged into your dashboard
    • message (required) – your message

    Some optional parameters may be included:

    • device – your user’s device name to send the message directly to that device, rather than all of the user’s devices (multiple devices may be separated by a comma)
    • title – your message’s title, otherwise your app’s name is used
    • url – a supplementary URL to show with your message
    • url_title – a title for your supplementary URL, otherwise just the URL is shown
    • priority – send as -2 to generate no notification/alert, -1 to always send as a quiet notification, 1 to display as high-priority and bypass the user’s quiet hours, or 2 to also require confirmation from the user
    • timestamp – a Unix timestamp of your message’s date and time to display to the user, rather than the time your message is received by our API
    • sound – the name of one of the sounds supported by device clients to override the user’s default sound choice

Note: Im hoping to transfer the script to GitHub soon.

<#         
    .NOTES
===========================================================================
    Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.139     
    Created by:   Terence Beggs
    Organization: SCConfigMgr
    Filename:     Push-OSDNotification.ps1      
===========================================================================
    .DESCRIPTION
       	This uses the PushOver notification service   

    .SOCIAL
        Twitter : @terencebeggs
        Blog : https://msendpointmgr.com

    .CHANGELOG
        Version 1.0
        Version 1.1 - added _SMSTSPackageName and _SMSTSLogPath(removed)
        Version 1.2 - added bios, make, model etc
        Version 1.3 - Script clean up
   	
    .EXAMPLE
        Change the variables as needed
Send-Pushover -Message "<h4 style=color:blue;>$env:COMPUTERNAME</h4> <p><b>$TS</b> has completed successfully at <b>$DateTime</b></p> <p><b>IPAddress:</b>$IPAddress </p> <p>IPAddress:$IPAddress </p>" -Token  -User -MessageTitle "OSD Completed Successfully" -SendAsHTML -URL "\\Server\contentlib$\Logs\$env:COMPUTERNAME" -URLTitle "Logs Location"
#>

# Optional for using with Task Sequence Var 
# $TSenv = New-Object -COMObject Microsoft.SMS.TSEnvironment

$DriveInfo = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId='C:'"
$PSCustomObject = [PSCustomObject]@{
  DateTime 		= (Get-Date -Format g)
  Time			= (Get-Date -format HH:mm)
  Make			= (Get-WmiObject -Class Win32_BIOS).Manufacturer
  Model			= (Get-WmiObject -Class Win32_ComputerSystem).Model
  ComputerName	= (Get-WmiObject -Class Win32_ComputerSystem).Name
  SerialNumber	= (Get-WmiObject win32_bios).SerialNumber
  IPAddress		= (Get-WmiObject win32_Networkadapterconfiguration | Where-Object{ $_.ipaddress -notlike $null }).IPaddress | Select-Object -First 1
  Drive			= $DriveInfo | Select-Object -ExpandProperty DeviceID
  DiskSize		= ($DriveInfo.Size/1GB -as [int]).ToString()
  FreeSpace		= [math]::Round($DriveInfo.Freespace/1GB, 2)
}

# Where the logs are stored at the end of the TS
$URL = "\\server\contentlibrary$\Logs\$env:COMPUTERNAME"

# URL Title
$URLTitle = "$Name Logs"

# API location
$uri = "https://api.pushover.net/1/messages.json"

# Combine drive info to string
$DiskInfo = "Drive={0} DiskSize GB={1} FreeSpace GB={2}" -f $PSCustomObject.Drive, $PSCustomObject.DiskSize, $PSCustomObject.FreeSpace

# Passes the parameters to Invoke-RestMethod
$parameters = @{
  # Message Title
  title	= "OSD Completed Successfully"
  # Send as Html
  html	= "1"
  # Device or Device Group Key
  token	= "APP_KEY"
  # User Key
  user	= "USER_KEY"
  # Url title appears at the bottom
  url_title = $URLTitle
  url		= $URL
  # Message Contents
  message   = "<p>Hello
    Operating System Deployment <strong><span style=color:green>Completed Successfully</span></strong> 
  on computer: <span style=color:blue><strong>$env:COMPUTERNAME</strong></span>
 
    <span style=color:blue><strong>Deployment Details :</strong></span>
    <strong>Computer name: </strong>   $($PSCustomObject.ComputerName) 
    <strong>Time Finished: </strong>  $($PSCustomObject.DateTime)
    <strong>IP: </strong> $($PSCustomObject.IPAddress)
    <strong>Make: </strong> $($PSCustomObject.Make)
    <strong>Model: </strong>  $($PSCustomObject.Model)
    <strong>Serial: </strong>  $($PSCustomObject.SerialNumber)
    <strong>Deployment Share: </strong>  $DiskInfo  
    </span>
</p>"
}

$parameters | Invoke-RestMethod -Uri $uri -Method Post -ContentType 'application/x-www-form-urlencoded'

Breaking down the script

I have tried to break down a few sections to make it easier to alter for your environment.

Hardware information

This basic information helps my support team but can be alter to display anything.

$DriveInfo = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId='C:'"
$PSCustomObject = [PSCustomObject]@{
DateTime = (Get-Date -Format g)
Time = (Get-Date -format HH:mm)
Make = (Get-WmiObject -Class Win32_BIOS).Manufacturer
Model = (Get-WmiObject -Class Win32_ComputerSystem).Model
ComputerName = (Get-WmiObject -Class Win32_ComputerSystem).Name
SerialNumber = (Get-WmiObject win32_bios).SerialNumber
IPAddress = (Get-WmiObject win32_Networkadapterconfiguration | Where-Object{ $_.ipaddress -notlike $null }).IPaddress | Select-Object -First 1
Drive = $DriveInfo | Select-Object -ExpandProperty DeviceID
DiskSize = ($DriveInfo.Size/1GB -as [int]).ToString()
FreeSpace = [math]::Round($DriveInfo.Freespace/1GB, 2)
}
Logs

In my environment I have MDT integrated and when a TS is finished the logs are transferred to a network share for review later.

# Where the logs are stored at the end of the TS
$URL = "\\server\contentlibrary$\Logs\$env:COMPUTERNAME"

# URL Title
$URLTitle = "$env:COMPUTERNAME Logs"

====================================

# Url title appears at the bottom
url_title = $URLTitle
url = $URL
Message

Its important to be careful of formatting as its HTML so follow https://www.w3schools.com/tags/

message   = "<p>Hello
Operating System Deployment <strong><span style=color:green>Completed Successfully</span></strong> 
on computer: <span style=color:blue><strong>$env:COMPUTERNAME</strong></span>
 
<span style=color:blue><strong>Deployment Details :</strong></span>
<strong>Computer name: </strong>   $($PSCustomObject.ComputerName) 
<strong>Time Finished: </strong>  $($PSCustomObject.DateTime)
<strong>IP: </strong> $($PSCustomObject.IPAddress)
<strong>Make: </strong> $($PSCustomObject.Make)
<strong>Model: </strong>  $($PSCustomObject.Model)
<strong>Serial: </strong>  $($PSCustomObject.SerialNumber)
<strong>Deployment Share: </strong>  $DiskInfo  
</span>
</p>"

I created two scripts one for success and failure and placed them in different parts of the TS, pretty sure you can work out where.

Well I hope you find this interesting and it makes sense, please feel free to comment if you have any questions.

Thanks

(6496)

Terence Beggs

An Irish man living in London, after completing a BSc in Computer Science in 2005 he started working in the IT Industry. Currently Senior Systems Officer at London Metropolitan University managing Azure and several thousand endpoints across several campuses in London. Technology focuses include SCCM, MDT, Azure, Office 365, Active Directory, Group Policy, Application Packaging, PowerShell, Virtualization and Automation.

12 comments

  • Hi Terence,
    Just stubbled over this fine article of yours and it looks really cool…:) Just have one question is this only mend to notification for me as an it technician or is it possible to use it for the end user as well. Iā€™m thinking the user is somehow prompted to insert there mobile number and they will get the completed message.

    Thanks Henrik Elgaard

    • As you have to add users to groups in Pushover, the user would need to set up and account first so you can’t just add a phone number.

  • Hi,

    Great info as always., I once created a tool that sent me data back via pushbullet. I have dropped a copy of the code here https://codeshare.io/50Q0WQ

    I can’t find the source on the internet where I originally found it. I just tested the code and it still works fine.

  • Cool stuff! šŸ˜‰

    As Telegram Messenger also supports API it should work with Telegram as well… Will test…

    • Thanks, im looking at Teams and pushbullet at the moment but i will add that to the list. Work and life are kicking my back side at the moment but will blog soon about these.

  • This is really cool. My coworker and I loved this idea after I saw this article yesterday. So we started to nerd out.

    We just implemented a OSD start and OSD finish notification to a Microsoft Teams’ channel webhook using your concept as inspiration!

    • Hello Max, i had a quick look at this and Pushbullet does have an API, im on vacation for a week so will try to have a look at it and update the post.
      Thanks

Sponsors