Good Day
I am creating toast notifications from within a PowerShell script and there is a "more information" button that I have added as an action.
<toast>
<actions>
<action arguments="http://google.com" content="more information" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
This works fine however it launches Microsoft Edge Chromium without bringing it to the foreground. So if you already have Edge open it feels at first glance like clicking the button on the notification did nothing. The page does open, just not in your face like you'd hope when asking for "more information". I am hoping to have it show up on top and right in your face as my users vary WILDLY in skill/knowledge.
I am looking for a solution where I can do one of the following:
I thought at first it may be behavior related to Edge itself however typing "http://google.com" into a Windows Run Dialog absolutely brings it to the front. (as I expect it too)
In case its a factor. PowerShell 5.1 is preferred however 7 is an option for me.
Thanks for any help you may be able to provide.
---Addtional Info---
This is for all sites launched from a toast notification using this method. I unfortunately do not have anything to use to test a non custom notification to see if it does the same thing or not.
The XML above is used to create the toast notification. Here is the PowerShell code that might help make more sense of it.
$ToastTitle = "TOAST NOTIFICATION"
$Signature = "From TEAMNAME"
$BannerImage = "C:\temp\toast-test\toast.jpg"
$EventTitle = "Testing Title"
$EventText = "This is where there would normally be info. This is just a test though."
$site = "http://google.com/"
$MoreInfoTitle = "More Information"
$FirstName = (net user $env:USERNAME /domain | Select-String "Full Name").ToString().Split(",")[-1].trim()
if ($FirstName) {
$CustomHello = "$CustomHello $FirstName"
}
#Specify Launcher App ID, the App that will claim ownership of the toast notification, doesn't affect functionality.
$LauncherID = "AppName"
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
#Build XML Template
[xml]$toastTemplate = @"
<toast duration="long" scenario="reminder">
<visual>
<binding template="ToastGeneric">
<text>$CustomHello</text>
<text>$ToastTitle</text>
<text placement="attribution">$Signature</text>
<image placement="hero" src="$BannerImage"/>
<group>
<subgroup>
<text hint-style="title" hint-wrap="true" >$EventTitle</text>
</subgroup>
</group>
<group>
<subgroup>
<text hint-style="body" hint-wrap="true" >$EventText</text>
</subgroup>
</group>
</binding>
</visual>
<audio src="ms-winsoundevent:notification.default"/>
</toast>
"@
[xml]$ToastActionSnooze = @"
<toast>
<actions>
<input id="SnoozeTimer" type="selection" title="Select a Snooze Interval" defaultInput="15">
<selection id="15" content="15 Minutes"/>
<selection id="30" content="30 Minutes"/>
<selection id="60" content="1 Hour"/>
<selection id="120" content="2 Hours"/>
<selection id="240" content="4 Hours"/>
</input>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action activationType="system" arguments="snooze" hint-inputId="SnoozeTimer" content="" id="test-snooze"/>
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
[xml]$ToastAction = @"
<toast>
<actions>
<action arguments="$site" content="$MoreInfoTitle" activationType="protocol" />
<action arguments="dismiss" content="" activationType="system"/>
</actions>
</toast>
"@
#If the Snooze parameter was passed, add additional XML elements to Toast
If ($Snooze) {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastActionSnooze.toast.actions, $true))
}
else {
[void]$ToastTemplate.toast.AppendChild($ToastTemplate.ImportNode($ToastAction.toast.actions, $true))
}
#Prepare XML
$ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
$ToastXml.LoadXml($ToastTemplate.OuterXml)
#Prepare and Create Toast
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)```
You nearly had it right. Just take this LauncherId
$LauncherID = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
and use this last line of code:
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)