From 78f1a5bdda0d381ff14bc8ba754df9bee2e432da Mon Sep 17 00:00:00 2001 From: Zacgoose <107489668+Zacgoose@users.noreply.github.com> Date: Wed, 8 Apr 2026 22:21:40 +0800 Subject: [PATCH] Better removal script --- enterprise/Remove-Windows-Chrome-and-Edge.ps1 | 151 ++---------------- 1 file changed, 12 insertions(+), 139 deletions(-) diff --git a/enterprise/Remove-Windows-Chrome-and-Edge.ps1 b/enterprise/Remove-Windows-Chrome-and-Edge.ps1 index cad4445e..e86b04a6 100644 --- a/enterprise/Remove-Windows-Chrome-and-Edge.ps1 +++ b/enterprise/Remove-Windows-Chrome-and-Edge.ps1 @@ -17,155 +17,28 @@ function Remove-ExtensionSettings { [string]$ExtensionSettingsKey ) - # Remove properties from managed storage key + # Remove all managed policy values and nested keys created for this extension. if (Test-Path $ManagedStorageKey) { - $propertiesToRemove = @( - "showNotifications", - "enableValidPageBadge", - "enablePageBlocking", - "enableCippReporting", - "cippServerUrl", - "cippTenantId", - "customRulesUrl", - "updateInterval", - "enableDebugLogging" - ) - - foreach ($property in $propertiesToRemove) { - if (Get-ItemProperty -Path $ManagedStorageKey -Name $property -ErrorAction SilentlyContinue) { - Remove-ItemProperty -Path $ManagedStorageKey -Name $property -Force -ErrorAction SilentlyContinue - Write-Host "Removed property: $property from $ManagedStorageKey" - } - } - - # Remove URL allowlist subkey and all its properties - $urlAllowlistKey = "$ManagedStorageKey\urlAllowlist" - if (Test-Path $urlAllowlistKey) { - # Remove all numbered properties (1, 2, 3, etc.) - $properties = Get-ItemProperty -Path $urlAllowlistKey -ErrorAction SilentlyContinue - if ($properties) { - $properties.PSObject.Properties | Where-Object { $_.Name -match '^\d+$' } | ForEach-Object { - Remove-ItemProperty -Path $urlAllowlistKey -Name $_.Name -Force -ErrorAction SilentlyContinue - Write-Host "Removed URL allowlist property: $($_.Name) from $urlAllowlistKey" - } - } - # Remove the urlAllowlist subkey if it's empty - try { - Remove-Item -Path $urlAllowlistKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed URL allowlist subkey: $urlAllowlistKey" - } catch { - # Key may not be empty or may have been removed already - } - } - - # Remove generic webhook subkey and event properties - $genericWebhookKey = "$ManagedStorageKey\genericWebhook" - if (Test-Path $genericWebhookKey) { - $webhookEventsKey = "$genericWebhookKey\events" - if (Test-Path $webhookEventsKey) { - $eventProperties = Get-ItemProperty -Path $webhookEventsKey -ErrorAction SilentlyContinue - if ($eventProperties) { - $eventProperties.PSObject.Properties | Where-Object { $_.Name -match '^\d+$' } | ForEach-Object { - Remove-ItemProperty -Path $webhookEventsKey -Name $_.Name -Force -ErrorAction SilentlyContinue - Write-Host "Removed webhook event property: $($_.Name) from $webhookEventsKey" - } - } - try { - Remove-Item -Path $webhookEventsKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed webhook events subkey: $webhookEventsKey" - } catch { - # Key may not be empty or may have been removed already - } - } - - foreach ($property in @("enabled", "url")) { - if (Get-ItemProperty -Path $genericWebhookKey -Name $property -ErrorAction SilentlyContinue) { - Remove-ItemProperty -Path $genericWebhookKey -Name $property -Force -ErrorAction SilentlyContinue - Write-Host "Removed generic webhook property: $property from $genericWebhookKey" - } - } - - try { - Remove-Item -Path $genericWebhookKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed generic webhook subkey: $genericWebhookKey" - } catch { - # Key may not be empty or may have been removed already - } - } - - # Remove custom branding subkey and all its properties - $customBrandingKey = "$ManagedStorageKey\customBranding" - if (Test-Path $customBrandingKey) { - $brandingPropertiesToRemove = @( - "companyName", - "productName", - "supportEmail", - "supportUrl", - "privacyPolicyUrl", - "aboutUrl", - "primaryColor", - "logoUrl" - ) - - foreach ($property in $brandingPropertiesToRemove) { - if (Get-ItemProperty -Path $customBrandingKey -Name $property -ErrorAction SilentlyContinue) { - Remove-ItemProperty -Path $customBrandingKey -Name $property -Force -ErrorAction SilentlyContinue - Write-Host "Removed custom branding property: $property from $customBrandingKey" - } - } - - # Remove the customBranding subkey if it's empty - try { - Remove-Item -Path $customBrandingKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed custom branding subkey: $customBrandingKey" - } catch { - # Key may not be empty or may have been removed already - } - } - - # Remove the managed storage key if it's empty try { - $remainingProperties = Get-ItemProperty -Path $ManagedStorageKey -ErrorAction SilentlyContinue - if ($remainingProperties -and $remainingProperties.PSObject.Properties.Count -eq 0) { - Remove-Item -Path $ManagedStorageKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed managed storage key: $ManagedStorageKey" - } + Remove-Item -Path $ManagedStorageKey -Recurse -Force -ErrorAction Stop + Write-Host "Removed managed storage key: $ManagedStorageKey" } catch { - # Key may not be empty or may have been removed already + Write-Warning "Failed to remove managed storage key: $ManagedStorageKey. Error: $($_.Exception.Message)" } + } else { + Write-Host "Managed storage key not found (already removed): $ManagedStorageKey" } - # Remove properties from extension settings key + # Remove extension install/settings key for this extension. if (Test-Path $ExtensionSettingsKey) { - $extensionPropertiesToRemove = @( - "installation_mode", - "update_url" - ) - - # Add browser-specific toolbar properties - if ($ExtensionId -eq $edgeExtensionId) { - $extensionPropertiesToRemove += "toolbar_state" - } elseif ($ExtensionId -eq $chromeExtensionId) { - $extensionPropertiesToRemove += "toolbar_pin" - } - - foreach ($property in $extensionPropertiesToRemove) { - if (Get-ItemProperty -Path $ExtensionSettingsKey -Name $property -ErrorAction SilentlyContinue) { - Remove-ItemProperty -Path $ExtensionSettingsKey -Name $property -Force -ErrorAction SilentlyContinue - Write-Host "Removed extension setting property: $property from $ExtensionSettingsKey" - } - } - - # Remove the extension settings key if it's empty try { - $remainingProperties = Get-ItemProperty -Path $ExtensionSettingsKey -ErrorAction SilentlyContinue - if ($remainingProperties -and $remainingProperties.PSObject.Properties.Count -eq 0) { - Remove-Item -Path $ExtensionSettingsKey -Force -ErrorAction SilentlyContinue - Write-Host "Removed extension settings key: $ExtensionSettingsKey" - } + Remove-Item -Path $ExtensionSettingsKey -Recurse -Force -ErrorAction Stop + Write-Host "Removed extension settings key: $ExtensionSettingsKey" } catch { - # Key may not be empty or may have been removed already + Write-Warning "Failed to remove extension settings key: $ExtensionSettingsKey. Error: $($_.Exception.Message)" } + } else { + Write-Host "Extension settings key not found (already removed): $ExtensionSettingsKey" } Write-Host "Completed removal of extension settings for $ExtensionId"