PowerShell/Scripts/show-notification.ps1

30 lines
989 B
PowerShell
Raw Normal View History

2022-08-13 15:34:35 +02:00
<#
.SYNOPSIS
Show Notification
.DESCRIPTION
This PowerShell script shows a toast-message notification for the Windows 10 Notification Center.
.EXAMPLE
2022-08-25 08:36:55 +02:00
PS> ./show-notification "Hello World"
2022-08-13 15:34:35 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2022-08-25 08:36:55 +02:00
param([string]$Text = "Hello World", [string]$Title = "NOTE", [int]$Duration = 5000)
2022-08-13 15:34:35 +02:00
try {
Add-Type -AssemblyName System.Windows.Forms
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$balloon.BalloonTipText = $Text
$balloon.BalloonTipTitle = $Title
$balloon.Visible = $true
2022-08-25 08:36:55 +02:00
$balloon.ShowBalloonTip($Duration)
2022-08-13 15:34:35 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}