From 469c5928f4b11be0b19fd902583d665b24c42438 Mon Sep 17 00:00:00 2001 From: 924312 <924312@gmail.com> Date: Thu, 11 Jun 2026 14:41:03 +1200 Subject: [PATCH] Update Config-uBlock-Lite.ps1 Changed parameters to use arrays rather than JSON strings Changed a couple functions to use elseif rather than else for clarity --- Config-uBlock-Lite.ps1 | 119 +++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 40 deletions(-) diff --git a/Config-uBlock-Lite.ps1 b/Config-uBlock-Lite.ps1 index 049d6b1..ee64978 100644 --- a/Config-uBlock-Lite.ps1 +++ b/Config-uBlock-Lite.ps1 @@ -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 @@ -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 @@ -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 @@ -76,37 +81,51 @@ 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 @@ -114,7 +133,8 @@ Function Get-ExtensionPolicyPath { return "$(Get-BrowserPolicyPath $Browser)\3rdparty\extensions\$ExtensionID\policy" } -Function Set-RegistryProperty { +function Set-RegistryProperty +{ Param( [string]$Path, [string]$Name, @@ -123,16 +143,19 @@ 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 @@ -140,19 +163,23 @@ Function Initialize-ExtensionPath { $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 @@ -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 } @@ -183,8 +213,10 @@ $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 } @@ -192,29 +224,36 @@ If ($RemoveConfiguration) { # 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 }