#Function to send notifications to user function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) { #Add XML variables [xml]$ToastTemplate = @" $Title $Message $Balise "@ #Check if running account is system or interactive logon $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4") #if not "Interactive" user, run as system if ($currentPrincipal -eq $false){ #Save XML to File $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\config\" if (!(Test-Path $ToastTemplateLocation)){ New-Item -ItemType Directory -Force -Path $ToastTemplateLocation } $ToastTemplate.Save("$ToastTemplateLocation\notif.xml") #Run Notify scheduled task to notify conneted users Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue } #else, run as connected user else{ #Load Assemblies [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 #Prepare XML $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New() $ToastXml.LoadXml($ToastTemplate.OuterXml) #Specify Launcher App ID $LauncherID = "Windows.SystemToast.Winget.Notification" #Prepare and Create Toast $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml) $ToastMessage.Tag = $ToastTemplate.toast.tag [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage) } #Wait for notification to display Start-Sleep 3 } }