param( [Parameter(Mandatory = $true)][string]$Title, [Parameter(Mandatory = $true)][string]$Body, [int]$Sound = 1 ) $ErrorActionPreference = 'Stop' $shown = $false try { [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 $t = [System.Security.SecurityElement]::Escape($Title) $b = [System.Security.SecurityElement]::Escape($Body) $xmlText = @" $t $b Goofish Watcher "@ $xml = New-Object Windows.Data.Xml.Dom.XmlDocument $xml.LoadXml($xmlText) $toast = New-Object Windows.UI.Notifications.ToastNotification $xml $appIds = @( '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe', 'Microsoft.PowerShell', 'GoofishWatcher' ) foreach ($id in $appIds) { try { [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($id).Show($toast) $shown = $true break } catch { } } } catch { } if ($Sound -gt 0) { for ($i = 0; $i -lt $Sound; $i++) { try { [System.Media.SystemSounds]::Exclamation.Play() } catch { } if ($i -lt $Sound - 1) { Start-Sleep -Milliseconds 500 } } } if (-not $shown) { try { $sh = New-Object -ComObject WScript.Shell $null = $sh.Popup("$Title`n$Body", 8, "Goofish Watcher", 64) } catch { } }