From 9d70a0d8426225ba5a0f6e9f717fd34ca1d746d4 Mon Sep 17 00:00:00 2001 From: Ben Whitmore Date: Sun, 10 Jan 2021 22:21:37 +0000 Subject: [PATCH] Version 1.2.10 - 10/01/21 -Removed XMLOtherSource Parameter -Cleaned up XML formatting which removed unnecessary duplication when the Snooze parameter was passed. Action ChildNodes are now appended to ToastTemplate XML. --- InternetAccessProblems.xml | 9 -- LeaveComputerSwitchedOn.xml | 9 -- MicrosoftExchangeLimitedFunctionality.xml | 9 -- PhoneSystemProblems.xml | 9 -- Toast_Notify.ps1 | 113 ++++++++++------------ 5 files changed, 52 insertions(+), 97 deletions(-) delete mode 100644 InternetAccessProblems.xml delete mode 100644 LeaveComputerSwitchedOn.xml delete mode 100644 MicrosoftExchangeLimitedFunctionality.xml delete mode 100644 PhoneSystemProblems.xml diff --git a/InternetAccessProblems.xml b/InternetAccessProblems.xml deleted file mode 100644 index 4269ff6..0000000 --- a/InternetAccessProblems.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - We want to bring to your attention some important information. Please review the details below before contacting the Service Desk - Sent on behalf of the ICT Service Desk - Internet Access Problems - We are currently experiencing intermittent problems with internet access. We are working with our service provider and will provide an update shortly - Details - https://byteben.com - \ No newline at end of file diff --git a/LeaveComputerSwitchedOn.xml b/LeaveComputerSwitchedOn.xml deleted file mode 100644 index 80ef55e..0000000 --- a/LeaveComputerSwitchedOn.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - We want to bring to your attention some important information. Please review the details below before contacting the Service Desk - Sent on behalf of the ICT Service Desk - Scheduled Mainteneance - We are working on your computer later. Please log off when you leave the office today but leave the computer on. Thank You - Details - https://byteben.com - \ No newline at end of file diff --git a/MicrosoftExchangeLimitedFunctionality.xml b/MicrosoftExchangeLimitedFunctionality.xml deleted file mode 100644 index 5f7a749..0000000 --- a/MicrosoftExchangeLimitedFunctionality.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - We want to bring to your attention some important information. Please review the details below before contacting the Service Desk - Sent on behalf of the ICT Service Desk - Microsoft Exchange Limited Functionality - We are currently experiencing problems with the email system. We are working with our service provider and will provide an update shortly - Details - https://byteben.com - \ No newline at end of file diff --git a/PhoneSystemProblems.xml b/PhoneSystemProblems.xml deleted file mode 100644 index 2ed7398..0000000 --- a/PhoneSystemProblems.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - We want to bring to your attention some important information. Please review the details below before contacting the Service Desk. - Sent on behalf of the ICT Service Desk - Phone System Problems - We are currently experiencing problems with our phone system. We are working with our service provider and will provide an update shortly. - Details - https://byteben.com - \ No newline at end of file diff --git a/Toast_Notify.ps1 b/Toast_Notify.ps1 index 5c62f9c..94adf1c 100644 --- a/Toast_Notify.ps1 +++ b/Toast_Notify.ps1 @@ -5,19 +5,23 @@ Created by: Ben Whitmore Filename: Toast_Notify.ps1 =========================================================================== -Version 1.2 - 09/01/21 -Added logic so if the script is deployed as SYSTEM it will create a scheduled task to run the script for the current logged on user. +Version 1.2.10 - 10/01/21 +-Removed XMLOtherSource Parameter +-Cleaned up XML formatting which removed unnecessary duplication when the Snooze parameter was passed. Action ChildNodes are now appended to ToastTemplate XML. -Special Thanks to: - -Inspiration for creating a Scheduled Task for Toasts @PaulWetter https://wetterssource.com/ondemandtoast -Inspiration for running Toasts in User Context @syst_and_deploy http://www.systanddeploy.com/2020/11/display-simple-toast-notification-for.html -Inspiration for creating scheduled tasks for the logged on user @ccmexec via Community Hub in ConfigMgr https://github.com/Microsoft/configmgr-hub/commit/e4abdc0d3105afe026211805f13cf533c8de53c4 +Version 1.2 - 09/01/21 +-Added logic so if the script is deployed as SYSTEM it will create a scheduled task to run the script for the current logged on user. + +-Special Thanks to: - +-Inspiration for creating a Scheduled Task for Toasts @PaulWetter https://wetterssource.com/ondemandtoast +-Inspiration for running Toasts in User Context @syst_and_deploy http://www.systanddeploy.com/2020/11/display-simple-toast-notification-for.html +-Inspiration for creating scheduled tasks for the logged on user @ccmexec via Community Hub in ConfigMgr https://github.com/Microsoft/configmgr-hub/commit/e4abdc0d3105afe026211805f13cf533c8de53c4 Version 1.1 - 30/12/20 -Added Snooze Switch option +-Added Snooze Switch option Version 1.0 - 22/07/20 -Release +-Release .SYNOPSIS The purpose of the script is to create simple Toast Notifications in Windows 10 @@ -54,13 +58,12 @@ Param ( [Parameter(Mandatory = $False)] [Switch]$Snooze, - [String]$XMLScriptDirSource = "CustomMessage.xml", - [String]$XMLOtherSource, + [String]$XMLSource = "CustomMessage.xml", [String]$ToastGUID ) -#Set Unique GUID for Toast if it is not passed to the script. This should only happen from the Scheduled Task -If (!($ToastGUID)){ +#Set Unique GUID for the Toast +If (!($ToastGUID)) { $ToastGUID = ([guid]::NewGuid()).ToString().ToUpper() } @@ -68,14 +71,6 @@ If (!($ToastGUID)){ $ScriptPath = $MyInvocation.MyCommand.Path $CurrentDir = Split-Path $ScriptPath -#Check if XML will come from the Script Source Directory or another source -If (!($PSBoundParameters.ContainsKey('XMLOtherSource') -eq $True)) { - $XMLPath = Join-Path $CurrentDir $XMLScriptDirSource -} -else { - $XMLPath = $XMLOtherSource -} - #Get Logged On User to prepare Scheduled Task $LoggedOnUserName = (Get-CimInstance -Namespace "root\cimv2" -ClassName Win32_ComputerSystem).Username $LoggedOnUserSID = (Get-CimInstance -Namespace "root\cimv2" -ClassName Win32_UserAccount | Where-Object { $_.Caption -eq $LoggedOnUserName }).SID @@ -142,18 +137,18 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq "NT AUT If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $LoggedOnUserName) { #Test if XML exists - if (!(Test-Path -Path $XMLPath)) { - throw "$XMLPath is invalid." + if (!(Test-Path -Path $XMLSource)) { + throw "$XMLSource is invalid." } #Check XML is valid $XMLToast = New-Object System.Xml.XmlDocument try { - $XMLToast.Load((Get-ChildItem -Path $XMLPath).FullName) + $XMLToast.Load((Get-ChildItem -Path $XMLSource).FullName) $XMLValid = $True } catch [System.Xml.XmlException] { - Write-Verbose "$XMLPath : $($_.toString())" + Write-Verbose "$XMLSource : $($_.toString())" $XMLValid = $False } @@ -161,7 +156,7 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged If ($XMLValid -eq $True) { #Read XML Nodes - [XML]$Toast = Get-Content $XMLPath + [XML]$Toast = Get-Content $XMLSource #Create Toast Variables $ToastTitle = $XMLToast.ToastContent.ToastTitle @@ -216,10 +211,8 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null - If (!$Snooze) { - - #Build XML Template when Snooze Timer is not specified - [xml]$ToastTemplate = @" + #Build XML ToastTemplate + [xml]$ToastTemplate = @" @@ -241,38 +234,12 @@ If (([System.Security.Principal.WindowsIdentity]::GetCurrent()).Name -eq $Logged "@ - } - else { - #Build XML Template when Snooze Timer is specified - [xml]$ToastTemplate = @" - - - - $CustomHello - $ToastTitle - $Signature - - - - - $EventTitle - - - - - $EventText - - - - -