From 7a583ef8d2458f6b4e86a16c82b0f597a3d4e15c Mon Sep 17 00:00:00 2001 From: kheldorn Date: Tue, 12 Apr 2022 20:49:35 +0200 Subject: [PATCH] Update New-ToastNotification.ps1 Do not display toast notification for application installations if the application in question is already marked as installed in WMI. See https://github.com/imabdk/Toast-Notification-Script/issues/13 --- New-ToastNotification.ps1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/New-ToastNotification.ps1 b/New-ToastNotification.ps1 index 638c0cf..a76a693 100644 --- a/New-ToastNotification.ps1 +++ b/New-ToastNotification.ps1 @@ -2552,6 +2552,21 @@ else { Write-Log -Level Warn -Message "Conditions for displaying toast notification for ADPasswordExpiration are not fulfilled" } +# Toast used for Application installation +if ($RunApplicationIDValue -and $RunApplicationIDEnabled -eq "True") { + $TestApplicationID = Get-CimInstance -ClassName CCM_Application -Namespace ROOT\ccm\ClientSDK -ErrorAction SilentlyContinue | Where-Object { $_.Id -eq $RunApplicationIDValue } + + if ($TestApplicationID -and $TestApplicationID.InstallState -eq "Installed") { + Write-Log -Message "Application $RunApplicationIDValue is already installed. Toast notification won't be displayed" + } + else { + Write-Log -Message "Application $RunApplicationIDValue is not installed. Displaying toast notification" + Display-ToastNotification + } + # Stopping script. No need to accidently run further toasts + break +} + # Toast not used for either OS upgrade or Pending reboot OR ADPasswordExpiration. Run this if all features are set to false in config.xml if (($UpgradeOS -ne "True") -AND ($PendingRebootCheck -ne "True") -AND ($PendingRebootUptime -ne "True") -AND ($ADPasswordExpiration -ne "True")) { Write-Log -Message "Toast notification is not used in regards to OS upgrade OR Pending Reboots OR ADPasswordExpiration. Displaying default toast"