PowerShell/Scripts/show-notification.ps1

31 lines
983 B
PowerShell
Raw Normal View History

2022-09-10 22:45:56 +02:00
<#
2022-08-13 15:34:35 +02:00
.SYNOPSIS
2022-09-06 21:42:04 +02:00
Shows a notification
2022-08-13 15:34:35 +02:00
.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 {
2022-09-10 22:45:56 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2022-09-06 21:42:04 +02:00
}