PowerShell/Docs/show-notification.md

91 lines
2.4 KiB
Markdown
Raw Normal View History

2023-07-29 10:34:04 +02:00
*show-notification.ps1*
================
2022-11-17 19:46:02 +01:00
This PowerShell script shows a toast-message notification for the Windows 10 Notification Center.
2023-07-29 10:04:38 +02:00
Parameters
----------
2022-11-17 19:46:02 +01:00
```powershell
2023-07-29 10:15:44 +02:00
PS> ./show-notification.ps1 [[-Text] <String>] [[-Title] <String>] [[-Duration] <Int32>] [<CommonParameters>]
2022-11-17 19:46:02 +01:00
-Text <String>
Required? false
Position? 1
Default value Hello World
Accept pipeline input? false
Accept wildcard characters? false
-Title <String>
Required? false
Position? 2
Default value NOTE
Accept pipeline input? false
Accept wildcard characters? false
-Duration <Int32>
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
PS> ./show-notification "Hello World"
```
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
2023-05-26 12:20:18 +02:00
This PowerShell script shows a toast-message notification for the Windows 10 Notification Center.
2022-11-17 20:02:26 +01:00
.EXAMPLE
2023-05-26 12:20:18 +02:00
PS> ./show-notification "Hello World"
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
#>
param([string]$Text = "Hello World", [string]$Title = "NOTE", [int]$Duration = 5000)
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
$balloon.ShowBalloonTip($Duration)
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
2023-08-06 21:36:33 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of show-notification.ps1 as of 08/06/2023 21:36:17)*