Forum Discussion
Paige__Tanner
Mar 11, 2024Brass Contributor
Clear notifications
Hello!
Is it possible to clear the current Windows notifications from PowerShell?
By notifications I mean the ones shown by the bell in the rightmost point of the taskbar. I don't want to avoid receiving notifications, but just to clear the ones that are present in this moment.
I am using Windows 11 and PowerShell 7.4.
The only solution I found is this one, but if I try
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
I got an error:
InvalidOperation: Unable to find type [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime].
both from a user shell and from an Administrator shell.
- Yes, because the RunTime isn't included in PowerShell 7.4. I'm afraid we can't fix that since the support for WinRT has been removed after just a few versions of PowerShell 7.
Paige__Tanner I tested this, and that works:
# get the list of all registry keys $notifications = Get-ChildItem HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications\Settings | Select-Object Name # iterate through the keys, extract the name that will be used in the clear function, and clear the notifications for ($index = 0; $index -lt $notifications.Count; $index++) { $name = $notifications[$index] $split = $name -split "\\" $last = $split[$split.Count - 1] $last = $last.Substring(0, $last.Length - 1) ([Windows.UI.Notifications.ToastNotificationManager]::History).clear($last) }
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If one of the posts was helpful in other ways, please consider giving it a Like.- Paige__TannerBrass Contributor
Harm_Veenstra Thanks for having tried. This doesn't work for me. Running the same script, I get many errors equal to this one:
InvalidOperation: C:\test_script.ps1:10 Line | 10 | ([Windows.UI.Notifications.ToastNotificationManager]::History).cl … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | Unable to find type [Windows.UI.Notifications.ToastNotificationManager].
which are probably related to the error mentioned in my first post. I wonder why my system does not have [Windows.UI.Notifications.ToastNotificationManager].
- Seems to be something with the built-in WinRT support that has been removed in PS7?