如何在 PowerShell 的桌面通知中添加新行

How do I add a new line in a desktop notification in PowerShell

这是项目

echo $ErrorActionPreference = "Stop"
echo $notificationTitle = "Aa1234567890"
echo [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
echo $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
echo $toastXml = [xml] $template.GetXml()
echo $toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
echo $xml = New-Object Windows.Data.Xml.Dom.XmlDocument
echo $xml.LoadXml($toastXml.OuterXml)
echo $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
echo $toast.Tag = "Test1"
echo $toast.Group = "Test2"
echo $toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(5)
echo $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("A7  WIFI  (password saved in clipboard)")
echo $notifier.Show($toast);

Currently, the notification appears like this

I want it to be like this

我想在通知中添加一个新行有没有办法,注意:我不想更改代码我只是想知道如何添加一个新行

正如@Jeroen Mostert 所说,您必须使用模板 ToastText02,您将能够使用 <text id="1">$Title</text> 作为标题,使用 <text id="2">$Text</text> 作为 xml

$ErrorActionPreference = "Stop"
$notificationTitle = "Aa1234567890"
$notificationText = "The password has been copied to the clipboard"
$AppID = "A7  WIFI"

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$toastXml = [xml] $template.GetXml()
($toastXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
($toastXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($toastXml.CreateTextNode($notificationText)) > $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($AppID)
$notifier.Show($toast)