2024-11-08 12:38:20 +01:00
|
|
|
The *show-notification.ps1* Script
|
|
|
|
===========================
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2024-11-08 12:35:11 +01:00
|
|
|
This PowerShell script shows a toast-message notification for the Windows Notification Center.
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
/home/markus/Repos/PowerShell/scripts/show-notification.ps1 [[-text] <String>] [[-title] <String>] [[-duration] <Int32>] [<CommonParameters>]
|
2022-11-17 19:46:02 +01:00
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
-text <String>
|
|
|
|
Specifies the text to show ('Hello World' by default)
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value Hello World
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
2024-05-19 10:25:56 +02:00
|
|
|
-title <String>
|
|
|
|
Specifies the title to show ('NOTE' by default)
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 2
|
|
|
|
Default value NOTE
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
2024-11-08 12:35:11 +01:00
|
|
|
-duration <Int32>
|
2024-05-19 10:25:56 +02:00
|
|
|
Specifies the view duration in milliseconds (5000 by default)
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 3
|
|
|
|
Default value 5000
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Example
|
|
|
|
-------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
PS> ./show-notification.ps1
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Notes
|
|
|
|
-----
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Related Links
|
|
|
|
-------------
|
2022-11-17 19:46:02 +01:00
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2023-05-26 12:20:18 +02:00
|
|
|
Shows a notification
|
2022-11-17 20:02:26 +01:00
|
|
|
.DESCRIPTION
|
2024-11-08 12:35:11 +01:00
|
|
|
This PowerShell script shows a toast-message notification for the Windows Notification Center.
|
2024-05-19 10:25:56 +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-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
2024-11-08 12:35:11 +01:00
|
|
|
PS> ./show-notification.ps1
|
2022-11-17 20:02:26 +01:00
|
|
|
.LINK
|
2023-05-26 12:20:18 +02:00
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-11-17 20:02:26 +01:00
|
|
|
.NOTES
|
2023-05-26 12:20:18 +02:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2022-11-17 20:02:26 +01:00
|
|
|
#>
|
|
|
|
|
2024-11-08 12:35:11 +01:00
|
|
|
param([string]$text = "Hello World", [string]$title = "NOTE", [int]$duration = 5000)
|
2022-11-17 20:02:26 +01: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-19 10:25:56 +02:00
|
|
|
$balloon.BalloonTipText = $text
|
|
|
|
$balloon.BalloonTipTitle = $title
|
2022-11-17 20:02:26 +01:00
|
|
|
$balloon.Visible = $true
|
2024-11-08 12:35:11 +01:00
|
|
|
$balloon.ShowBalloonTip($duration)
|
2022-11-17 20:02:26 +01:00
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:52:00)*
|