Conversation
There was a problem hiding this comment.
Pull request overview
This PR simplifies the Windows Chrome/Edge removal script by switching from per-value cleanup to deleting the extension’s policy registry key subtrees, aiming to more reliably remove all settings associated with the extension.
Changes:
- Replace granular registry value deletion with
Remove-Item -Recurseon the managed storage policy key. - Replace granular extension policy value deletion with
Remove-Item -Recurseon theExtensionSettings\<extensionId>key. - Add clearer “not found” and failure warning output paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # 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" |
There was a problem hiding this comment.
The new approach deletes the entire managed storage registry key subtree (Remove-Item ... -Recurse) rather than removing specific policy values. That’s a behavior change that can remove any additional admin-set values under this key (not just those created by this repo’s deployment script). If the intent is to only undo what the deployment script sets, consider reverting to targeted value removal or at least tightening the comment/log messaging to explicitly state that the whole key is deleted.
| # 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" |
There was a problem hiding this comment.
Similarly, deleting the entire ExtensionSettings\<extensionId> key will remove any additional Chrome/Edge extension policy values that may have been configured outside this repo (e.g., allow/deny host lists or other extension-specific policies). If the goal is only to remove install enforcement, consider removing just installation_mode, update_url, and toolbar pin values instead of the full key, or add a clear warning that all extension policy settings will be wiped.
| ) | ||
|
|
||
| # Remove properties from managed storage key | ||
| # Remove all managed policy values and nested keys created for this extension. |
There was a problem hiding this comment.
The comment says “Remove all managed policy values and nested keys created for this extension”, but the implementation deletes the entire registry key. To avoid confusion for operators, update the wording to explicitly indicate that the whole key (and everything under it) is removed.
| # Remove all managed policy values and nested keys created for this extension. | |
| # Remove the entire managed storage key for this extension, including all values and subkeys under it. |
No description provided.