Skip to content

Instantly share code, notes, and snippets.

@BladeWDR
Last active August 26, 2025 18:24
Show Gist options
  • Save BladeWDR/4de8b2575011356632470b1a0159628a to your computer and use it in GitHub Desktop.
Save BladeWDR/4de8b2575011356632470b1a0159628a to your computer and use it in GitHub Desktop.
Disable-BrowserNotifications.ps1
<#
.SYNOPSIS
Disables desktop notifications for major browsers
.DESCRIPTION
This script creates registry entries to disable desktop notifications for Chrome and Edge.
Works on both domain and non-domain Windows machines
.NOTES
Run as Administrator for HKLM registry modifications
#>
filter Assert-KeyExists
{
$exists = Test-Path -Path "$_"
if (!$exists)
{
New-Item -Path "$_" -ItemType Directory -Force
}
}
function Set-RegKey
{
param(
[string]$Path,
[string]$Name,
[string]$Value,
[string]$Type
)
$Path | Assert-KeyExists
if((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).Value -ne $Value)
{
Set-ItemProperty -Path $Path -Name $Name -Value "$Value"
} else
{
Write-host "nothing to do."
}
}
$ChromeRegPath = 'HKLM:\SOFTWARE\Policies\Google\Chrome'
$EdgeRegPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Edge'
$AllowUrlsKey = 'NotificationsAllowedForUrls'
$NotificationKeyName = 'DefaultNotificationsSetting'
# Ensure the subkey exists
$ChromeAllowPath = Join-Path $ChromeRegPath $AllowUrlsKey
$EdgeAllowPath = Join-Path $EdgeRegPath $AllowUrlsKey
$ChromeAllowPath | Assert-KeyExists
$EdgeAllowPath | Assert-KeyExists
Set-RegKey -Path "$ChromeRegPath" -Name "$NotificationKeyName" -Type DWORD -Value "2"
Set-RegKey -Path "$EdgeRegPath" -Name "$NotificationKeyName" -Type DWORD -Value "2"
$AllowedUrls = @(
"https://teams.microsoft.com",
"https://slack.com"
"https://outlook.com"
"https://outlook.office.com"
)
$i = 1
foreach ($url in $AllowedUrls)
{
New-ItemProperty -Path $ChromeAllowPath -Name $i -Value $url -PropertyType String -Force
New-ItemProperty -Path $EdgeAllowPath -Name $i -Value $url -PropertyType String -Force
$i++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment