Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 79 additions & 40 deletions Config-uBlock-Lite.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
Disable first run page. 1 = true, 0 = false

.PARAMETER NoFiltering
Trusted sites where uBlock Lite will be disabled. JSON array format: '["example.com", "trusted-site.org"]'
Trusted sites where uBlock Lite will be disabled. String array format: -NoFiltering "example.com", "trusted-site.org"

.PARAMETER DisabledFeatures
Disable specific user-facing features. JSON array format: '["dashboard", "develop", "filteringMode", "picker", "zapper"]'
Disable specific user-facing features. String array format: -DisabledFeatures "dashboard", "develop", "filteringMode", "picker", "zapper"
Options: dashboard (prevent setting changes), develop (prevent developer mode), filteringMode (prevent filtering mode changes), picker (prevent custom filters), zapper (prevent element removal)

.PARAMETER Rulesets
Enable/disable specific rulesets. JSON array format: '["+default", "+adguard-url-tracking", "-easylist-cookies"]'
Enable/disable specific rulesets. String array format: -Rulesets "+default", "+adguard-url-tracking", "-easylist-cookies"
Use + to enable, - to disable. Special value "-*" disables all non-default rulesets. See https://github.com/uBlockOrigin/uBOL-home/blob/main/chromium/rulesets/ruleset-details.json for ruleset IDs
NOTE: Max 10 rulesets are supported

Default rulesets (already enabled): ublock-filters, ublock-badware, ublock-privacy, ublock-unbreak, easylist, easyprivacy, plowe-0, urlhaus-full

Expand All @@ -45,7 +46,7 @@
- annoyances-notifications: Blocks notification prompts (EasyList)
- adguard-mobile: Mobile-specific ad blocking (AdGuard/uBO)

Example: '["+default", "+adguard-spyware-url", "+annoyances-cookies", "+annoyances-overlays"]'
Example: "+default", "+adguard-spyware-url", "+annoyances-cookies", "+annoyances-overlays"

.NOTES
Author: Martin Bengtsson
Expand All @@ -54,6 +55,10 @@
Extension: uBlock Origin Lite (Manifest V3)
Extension ID (Edge): cimighlppcgcoapaliogpjjdehbnofhn
Extension ID (Chrome): ddkjiahejlhfcafbddmgiahcphecmpfh

Modified by: John V
Source: https://github.com/imabdk/PowerShell/blob/master/Config-uBlock-Lite.ps1
Source: https://www.imab.dk/enterprise-ad-blocking-deploying-and-configuring-ublock-origin-lite-with-powershell-and-microsoft-intune/
#>

#Requires -RunAsAdministrator
Expand All @@ -76,45 +81,60 @@ Param(
[ValidateRange(0, 1)]
[int]$DisableFirstRunPage = 1,

[string]$NoFiltering = '["imab.dk", "contoso.com", "contoso.sharepoint.com", "app.powerbi.com", "community.powerbi.com", "intranet.contoso.com", "portal.contoso.com", "app.bundledocs.com"]',
[string[]]$NoFiltering = @("imab.dk", "contoso.com", "contoso.sharepoint.com", "app.powerbi.com", "community.powerbi.com", "intranet.contoso.com", "portal.contoso.com", "app.bundledocs.com"),

# Available features: "dashboard", "develop", "filteringMode", "picker", "zapper"
[string]$DisabledFeatures = '["dashboard"]',
[ValidateSet("dashboard", "develop", "filteringMode", "picker", "zapper")]
[string[]]$DisabledFeatures = @("dashboard"),

# Use +ruleset to enable, -ruleset to disable, -* to disable all except specified
# Ruleset IDs: https://github.com/uBlockOrigin/uBOL-home/blob/main/chromium/rulesets/ruleset-details.json
[string]$Rulesets = '["+default"]'
[string[]]$Rulesets = @("+default")
)

# Helper Functions
# Helper functions

Function Get-BrowserPolicyPath {
Param([string]$Browser)
if ($Browser -eq "Edge") {
function Get-BrowserPolicyPath
{
Param(
[string]$Browser
)
if( $Browser -eq "Edge" )
{
return "HKLM:\SOFTWARE\Policies\Microsoft\Edge"
} else {
}
elseif( $Browser -eq "Chrome" )
{
return "HKLM:\SOFTWARE\Policies\Google\Chrome"
}
}

Function Get-ExtensionID {
Param([string]$Browser)
if ($Browser -eq "Edge") {
function Get-ExtensionID
{
Param(
[string]$Browser
)
if( $Browser -eq "Edge" )
{
return "cimighlppcgcoapaliogpjjdehbnofhn"
} else {
}
elseif( $Browser -eq "Chrome" )
{
return "ddkjiahejlhfcafbddmgiahcphecmpfh"
}
}

Function Get-ExtensionPolicyPath {
function Get-ExtensionPolicyPath
{
Param(
[string]$Browser,
[string]$ExtensionID
)
return "$(Get-BrowserPolicyPath $Browser)\3rdparty\extensions\$ExtensionID\policy"
}

Function Set-RegistryProperty {
function Set-RegistryProperty
{
Param(
[string]$Path,
[string]$Name,
Expand All @@ -123,36 +143,43 @@ Function Set-RegistryProperty {
[string]$Type
)

Try {
try
{
New-ItemProperty -Path $Path -Name $Name -PropertyType $Type -Value $Value -Force -ErrorAction Stop | Out-Null
Write-Output "$LogPrefix Set '$Name' successfully"
}
Catch {
catch
{
Write-Output "$LogPrefix ERROR: Failed to set '$Name' - $($_.Exception.Message)"
}
}

Function Initialize-ExtensionPath {
function Initialize-ExtensionPath
{
Param(
[string]$Browser,
[string]$ExtensionID
)

$extensionPath = Get-ExtensionPolicyPath -Browser $Browser -ExtensionID $ExtensionID

Try {
if (-not (Test-Path $extensionPath)) {
try
{
if( ! (Test-Path $extensionPath) )
{
New-Item -Path $extensionPath -Force -ErrorAction Stop | Out-Null
}
return $extensionPath
}
Catch {
catch
{
Write-Output "$LogPrefix ERROR: Failed to create registry path - $($_.Exception.Message)"
return $null
}
}

Function Remove-ExtensionConfiguration {
function Remove-ExtensionConfiguration
{
Param(
[string]$Browser,
[string]$ExtensionID
Expand All @@ -162,12 +189,15 @@ Function Remove-ExtensionConfiguration {

$policyPath = Get-ExtensionPolicyPath -Browser $Browser -ExtensionID $ExtensionID

if (Test-Path -Path $policyPath) {
Try {
if( Test-Path -Path $policyPath )
{
try
{
Remove-Item -Path $policyPath -Recurse -Force -ErrorAction Stop
Write-Output "$LogPrefix Removed policy configuration"
}
Catch {
catch
{
Write-Output "$LogPrefix ERROR: Failed to remove configuration - $($_.Exception.Message)"
Exit 1
}
Expand All @@ -183,38 +213,47 @@ $LogPrefix = "[uBlock-Lite]"

# Remove Configuration Mode

If ($RemoveConfiguration) {
foreach ($BrowserName in $Browser) {
if( $RemoveConfiguration )
{
foreach( $BrowserName in $Browser )
{
$extensionID = Get-ExtensionID -Browser $BrowserName
Remove-ExtensionConfiguration -Browser $BrowserName -ExtensionID $extensionID
}
}

# Apply Configuration

$NoFilteringJSON = ConvertTo-Json -Compress @($NoFiltering | Sort-Object -Unique)
$DisabledFeaturesJSON = ConvertTo-Json -Compress @($DisabledFeatures | Sort-Object -Unique)
$RulesetsJSON = ConvertTo-Json -Compress @($Rulesets | Sort-Object -Unique)

$settings = @(
@{ Name = "defaultFiltering"; Value = $DefaultFiltering; Type = "String" }
@{ Name = "showBlockedCount"; Value = $ShowBlockedCount; Type = "DWord" }
@{ Name = "strictBlockMode"; Value = $StrictBlockMode; Type = "DWord" }
@{ Name = "disableFirstRunPage"; Value = $DisableFirstRunPage; Type = "DWord" }
@{ Name = "noFiltering"; Value = $NoFiltering; Type = "String" }
@{ Name = "disabledFeatures"; Value = $DisabledFeatures; Type = "String" }
@{ Name = "rulesets"; Value = $Rulesets; Type = "String" }
@{ Name = "defaultFiltering" ; Value = $DefaultFiltering ; Type = "String" }
@{ Name = "showBlockedCount" ; Value = $ShowBlockedCount ; Type = "DWord" }
@{ Name = "strictBlockMode" ; Value = $StrictBlockMode ; Type = "DWord" }
@{ Name = "disableFirstRunPage" ; Value = $DisableFirstRunPage ; Type = "DWord" }
@{ Name = "noFiltering" ; Value = $NoFilteringJSON ; Type = "String" }
@{ Name = "disabledFeatures" ; Value = $DisabledFeaturesJSON ; Type = "String" }
@{ Name = "rulesets" ; Value = $RulesetsJSON ; Type = "String" }
)

foreach ($BrowserName in $Browser) {
foreach( $BrowserName in $Browser )
{
$extensionID = Get-ExtensionID -Browser $BrowserName

Write-Output "$LogPrefix Configuring for $BrowserName"

$litePolicyPath = Initialize-ExtensionPath -Browser $BrowserName -ExtensionID $extensionID

if (-not $litePolicyPath) {
if( ! $litePolicyPath )
{
Write-Output "$LogPrefix ERROR: Failed to initialize extension path for $BrowserName"
Exit 1
}

foreach ($setting in $settings) {
foreach( $setting in $settings )
{
Write-Output "$LogPrefix Applying setting: $($setting.Name) = $($setting.Value)"
Set-RegistryProperty -Path $litePolicyPath -Name $setting.Name -Value $setting.Value -Type $setting.Type | Out-Null
}
Expand Down