Windows 10 のコマンド ラインから通知を作成する

Windows 10 のコマンド ラインから通知を作成する

キーボード ショートカットに関連付けられたスクリプトがあり、ショートカットをトリガーすると、スクリプトが実行されたことを確認する通知が表示されるようにしたいです。

スクリプト内から通知を作成するにはどうすればよいですか?

編集

Linuxでは、以前はcommand && notify-send "My message"

答え1

PowerShellでは(ここ):

[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"Script Completed!","Your script ran succesfully!",[system.windows.forms.tooltipicon]::None)

またはこれ(ここ):

$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: Your script has been completed successfully"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "Test1"
$toast.Group = "Test2"
$toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(5)
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Script Completed!")
$notifier.Show($toast);

関連情報