PowerShell/scripts/show-notification.ps1

30 lines
943 B
PowerShell
Raw Normal View History

2023-10-31 11:25:11 +01: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.
2022-08-13 15:34:35 +02:00
.EXAMPLE
2022-12-29 21:46:35 +01:00
PS> ./show-notification "Hello World"
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
#>
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-12-29 21:46:35 +01:00
}