Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Show-ToastNoficiation
- {
- <#
- .Synopsis
- Displays a Toast notification in Windows 10 with PowerShell
- .DESCRIPTION
- Displays a Toast notification in Windows 10 with PowerShell
- .EXAMPLE
- Show-ToastNotification -Title 'Script completed' -Body "Your script located at $Path completed"
- .EXAMPLE
- Show-ToastNotification -Title 'Script completed' -Body "Your script located at $Path completed" -Icon C:\Temp\Logo.png
- .INPUTS
- System.String
- .OUTPUTS
- None
- .NOTES
- (c) 2017 Shawn Esterman. All rights reserved.
- Follow me on Twitter @ShawnDotTweet
- I'll try and post more stuff on github.com/ShawnEsterman
- #>
- [CmdletBinding()]
- Param (
- [System.String] $Title,
- [System.String] $Body,
- [System.String] $Icon = "$PSScriptRoot\assets\Powershell_avatar.ico",
- [System.String] $Tag = (Get-Random -Minimum 0 -Maximum 99999),
- [System.String] $Group = 'poshToast',
- [System.String] $Notifier = 'ToastNotificationManager'
- )
- $Template = @"
- <toast displayTimestamp="$(Get-Date -Format u)">
- <visual>
- <binding template="ToastGeneric">
- <text hint-maxLines="1">$Title</text>
- <text>$Body</text>
- <text placement="attribution">via PowerShell</text>
- $(if (Test-Path $Icon) {"<image placement=`"appLogoOverride`" hint-crop=`"none`" src=`"$Icon`"/>"})
- </binding>
- </visual>
- </toast>
- "@
- $XmlDocument = New-Object Windows.Data.Xml.Dom.XmlDocument
- $XmlDocument.LoadXml($Template)
- $ToastNotification = [Windows.UI.Notifications.ToastNotification]::new($XmlDocument)
- $ToastNotification.Tag = $Tag
- $ToastNotification.Group = $Group
- $ToastNotification.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(5)
- $ToastNotifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($Notifier)
- $ToastNotifier.Show($ToastNotification)
- }
Add Comment
Please, Sign In to add comment