Mar 11 2024 02:02 AM
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.
Mar 11 2024 02:26 AM
@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.
Mar 11 2024 02:58 AM
@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].
Mar 11 2024 03:16 AM
Mar 11 2024 03:38 AM
Mar 11 2024 07:08 AM - edited Mar 11 2024 07:09 AM
It could be something similar, yes. Some missing module or framework? But what exactly?
I can only add that I tried your script also on Windows PowerShell 5.1 and in my case it gives error as well:
Unable to find type [Windows.UI.Notifications.ToastNotificationManager].
At C:\test_script.ps1:10 char:6
+ ([Windows.UI.Notifications.ToastNotificationManager]::History).cl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Windows.UI.Noti...ficationManager:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Mar 11 2024 07:17 AM
Mar 12 2024 03:33 PM
Mar 12 2024 04:02 PM
SolutionMar 13 2024 03:37 AM
Mar 12 2024 04:02 PM
Solution