This script takes a few parameters to create a Notification App. The App Name and Icon are the most important as these are what will appear in the toast notification.
Parameter documentation follows:
Parameter | Type | Description |
---|
IconURI | URI | The URI of the app icon to use for the notification app registration. This will be downloaded to the working directory. |
IconFileName | String | File name to use for the app icon. Optional. If not specified, the file name from the URI will be used. |
WorkingDirectory | DirectoryInfo | The working directory to use for the app icon. If not specified, 'C:\RMM\NotificationApp' will be used. |
AppId | String | The app ID to use for the notification app registration. Expected format is something like: 'CompanyName.AppName'. |
AppDisplayName | String | The app display name to use for the notification app registration. |
AppIconBackgroundColor | String | The background color to use for the app icon. Optional. If not specified, the background color will be transparent. Expected format is a hex value like 'FF000000' or '0' for transparent. |
ShowInSettings | Int | Show the app in the Windows Settings app. Optional. If not specified, the app will not be shown in the Settings app. |
The Script
Generic Example
$NotificationAppParams = @{
IconURI = 'https://homotechsual.dev/img/Icon.png'
IconFileName = 'homotechsual.png'
WorkingDirectory = 'C:\RMM\NotificationApp'
AppId = 'homotechsual.example'
AppDisplayName = 'Homotechsual Example'
AppIconBackgroundColor = 0
ShowInSettings = 1
}
Register-NotificationApp @NotificationAppParams
RMM Example
Unsurprisingly, I'm going to use NinjaOne as the example RMM here. So I've done the donkeywork that is best documented by NinjaOne themselves on the Dojo and added the script above to the NinjaOne Script Library - but what next?
Option 1: Same App for All Customers
Well the chances are that you want to use the same relatively small set of apps per customer so we'll just store a nice blob of text in the Ninja Script Library.
We could end up with a "Preset Parameter" set like this:
-IconURI https://homotechsual.dev/img/Icon.png -IconFileName homotechsual.png -WorkingDirectory C:\RMM\NotificationApp -AppId homotechsual.example -AppDisplayName "Homotechsual Example" -AppIconBackgroundColor 0 -ShowInSettings 1
You can have multiple preset parameter sets and simply select the one you want to use when you run the script or when you schedule it against a group (or however you want to run this) but what about getting more creative?
Option 2: Pull App Details per Customer
We can use Documentation fields to store the details of the app per client and then use the NinjaOne CLI to pull the details when we run the script. This is a little more work but it's worth it if you want to brand your notifications per customer.
We'll need to add a few fields to the NinjaOne Documentation tab for each client:
Field | Type | Description |
---|
NotificationIconURI | URL | The URI of the app icon to use for the notification app registration. This will be downloaded to the working directory. |
NotificationAppId | String | The app ID to use for the notification app registration. Expected format is something like: 'CompanyName.AppName'. |
NotificationAppDisplayName | String | The app display name to use for the notification app registration. |
NotificationAppBackgroundColor | String | The background color to use for the app icon. Optional. If not specified, the background color will be transparent. Expected format is a hex value like 'FF000000' or '0' for transparent. |
We can then use the NinjaOne CLI to pull the details for the client we're running the script against and use them to create the parameter set for the script.
This means editing our script a little to accept the parameters from the CLI and then using the NinjaOne CLI to pull the details from the Documentation tab. We're going to assume you called your Document Template Example Template
and your fields named as above in the table (with spaces between words if you wish).
At the top of the script we're going to replace the entire parameter block:
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[uri]$IconURI,
[string]$IconFileName,
[System.IO.DirectoryInfo]$WorkingDirectory = 'C:\RMM\NotificationApp\',
[Parameter(Mandatory)]
[string]$AppId,
[Parameter(Mandatory)]
[string]$AppDisplayName,
[ValidatePattern('^(0)$|^([A-F0-9]{8})$')]
[string]$AppIconBackgroundColor = 0,
[int]$ShowInSettings = 0
)
And replace it with this:
$IconURI = Ninja-Docs-Property-Get "Example Template" "NotificationIconURI"
$IconFileName = 'NotificationIcon.png'
$WorkingDirectory = 'C:\RMM\NotificationApp\'
$AppId = Ninja-Docs-Property-Get "Example Template" "NotificationAppId"
$AppDisplayName = Ninja-Docs-Property-Get "Example Template" "NotificationAppDisplayName"
$AppIconBackgroundColor = Ninja-Docs-Property-Get "Example Template" "NotificationAppBackgroundColor"
$ShowInSettings = 1
If done correctly, you should be able to run the script and have it pull the details from the Documentation tab for the client you're running it against. This could be improved by exiting the script if the required fields are not populated so we could add something like this after $ShowInSettings = 1
:
if (($null -eq $IconURI) -or ($null -eq $AppId) -or ($null -eq $AppDisplayName)) {
Write-Error "Required fields are not populated in the Documentation tab."
exit
}