2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2022-08-13 15:34:35 +02:00
|
|
|
|
.SYNOPSIS
|
2022-12-29 21:46:35 +01:00
|
|
|
|
Shows a notification
|
2022-08-13 15:34:35 +02:00
|
|
|
|
.DESCRIPTION
|
2022-12-29 21:46:35 +01:00
|
|
|
|
This PowerShell script shows a toast-message notification for the Windows 10 Notification Center.
|
2024-05-14 21:42:24 +02:00
|
|
|
|
.PARAMETER text
|
|
|
|
|
Specifies the text to show ('Hello World' by default)
|
|
|
|
|
.PARAMETER title
|
|
|
|
|
Specifies the title to show ('NOTE' by default)
|
|
|
|
|
.PARAMETER duration
|
|
|
|
|
Specifies the view duration in milliseconds (5000 by default)
|
2022-08-13 15:34:35 +02:00
|
|
|
|
.EXAMPLE
|
2024-05-14 21:42:24 +02:00
|
|
|
|
PS> ./show-notification
|
2022-08-13 15:34:35 +02:00
|
|
|
|
.LINK
|
2022-12-29 21:46:35 +01:00
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-08-13 15:34:35 +02:00
|
|
|
|
.NOTES
|
2022-12-29 21:46:35 +01:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2022-08-13 15:34:35 +02:00
|
|
|
|
#>
|
|
|
|
|
|
2024-05-14 21:42:24 +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
|
2024-05-14 21:42:24 +02:00
|
|
|
|
$balloon.BalloonTipText = $text
|
|
|
|
|
$balloon.BalloonTipTitle = $title
|
2022-08-13 15:34:35 +02:00
|
|
|
|
$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-12-29 21:46:35 +01:00
|
|
|
|
}
|