Skip to content

Instantly share code, notes, and snippets.

@ag-michael
Last active August 31, 2021 17:27
Show Gist options
  • Save ag-michael/7185fedf276b5a9d905449eb15e4f7cc to your computer and use it in GitHub Desktop.
Save ag-michael/7185fedf276b5a9d905449eb15e4f7cc to your computer and use it in GitHub Desktop.
Browser-Cleanup: Remove push notificaiton exemptions and non-exempt extensions
<#
.SYNOPSIS
Reset push-notification exceptions and remove non-exempt extensions.
With just the -User, it lists the changes that will be made.
.PARAMETER User
The User profile name name in C:\Users\
.PARAMETER Clean
Commit changes by removing notification exemptions and extensions directories
.PARAMETER KillBrowsers
Kill running browser processes
.EXAMPLE
PS> Browser-Cleanup.ps1 -KillBrowsers -Clean -User testuser
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[string]$User,
[Parameter(Mandatory=$False)]
[switch]$Clean=$false,
[Parameter(Mandatory=$False)]
[switch]$KillBrowsers=$false
)
$exempt_extensions=@("apdfllckaahabafndbhieahigkjlhalf","ghbmnnjooekpmoecnnnilnnbdlolhkhi","nmmhkkegccagdldgiimedpiccmgmieda","pkedcjkdefgpdelpbcmbmeomcjbeemfm")
#Kill Browsers
if($KillBrowsers){
Get-Process chrome| Stop-Process -Force
Get-Process msedge| Stop-Process -Force
}
$browser_profiles = New-Object Collections.Generic.List[string]
$browser_profiles.Add("C:\Users\$User\AppData\local\Chromium\User Data\Default\")
$browser_profiles.Add("C:\Users\$User\AppData\local\google\Chrome\User Data\Default\")
$browser_profiles.Add("C:\Users\$User\AppData\Local\Microsoft\Edge\User Data\Default\")
#reset notifications
foreach($profile in $browser_profiles){
try {
$prefs=(get-content "$profile\Preferences"| ConvertFrom-Json)
if($Clean){
$prefs.profile.content_settings.exceptions.notifications=@{}
$prefs|ConvertTo-Json -depth 100 |set-content "$profile\Preferences"
Write-Host "Resetted notification exemptions for $profile"
}
else {
Write-Host "Notifications for $profile :"
Write-Host ($prefs.profile.content_settings.exceptions.notifications|convertto-json)
}
foreach($extension in (ls "$profile\Extensions\")){
if(-not $exempt_extensions.Contains($extension.Name)){
$e=$extension.Name
if($Clean){
write-host "Removing $e for $profile"
rm -recurse -force "$profile\Extensions\$e"
}
else {
Write-Host "$profile\Extensions\$e eligible for removal"
}
}
}
} catch{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment