Open kheldorn opened 3 years ago
Thank you for the suggestion.
I usually suggest using the collections in configmgr for this purpose, but I see how collection refreshes combined with how often hardware inventory is run can results in unwanted toast notifications. Added to my 'might do-list'. Another possibility is that I add the option to only allow the toast notification to run once a day regardless of how the deployment schedule in configmgr may be configured.
It should be easy modification. Just add this code at start of function Display-ToastNotification:
if ($RunApplicationIDValue -and $RunApplicationIDEnabled -eq "True") {
$TestApplicationID = Get-CimInstance -ClassName CCM_Application -Namespace ROOT\ccm\ClientSDK -ea SilentlyContinue | Where-Object { $_.Id -eq $RunApplicationIDValue }
if ($TestApplicationID -and $TestApplicationID.InstallState -eq "Installed") {
Write-Log -Message "Application $RunApplicationID is already installed. Toast notification won't be displayed"
return
}
}
So in case, that you define RunApplicationID XML tag, and such application will be already installed, notification won't show. Of course this code can be placed earlier in the New-ToastNotification script, for sake of better effeciency..
I went a slightly different route and added the following code towards the end of the script, just before it defaults to the fallback toast notification.
# 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
}
Would it be possible to introduce an option that would let me not display a notification if the specified deployment is already installed?
I've set the following option in the XML:
<Option Name="RunApplicationID" Enabled="True" Value="ScopeId_968C5854-F7DB-48D1-B4AA-C4DCEAE28031/Application_6cee0155-d552-4067-9990-1946456585d5" />
But regardless of install state I get the notification.
In #2 a similar feature was already introduced to not show notifications for deployments that aren't available on the client.
Reason for the request: I'd love to use the script to advertise a software update. But I don't want the users to still receive the notifications when the update has already been installed. I'm well aware that this can also be achieve in other ways (compliance rules, dynamic collections, ...) but I'd like to keep the deployments as simple as possible. An additional option in the XML that enables a check whether the deployment was already installed would be much appreciated and make my work a lot easier.