Skip to content

Better removal script#141

Merged
Zacgoose merged 1 commit intoCyberDrain:devfrom
Zacgoose:removal-script
Apr 8, 2026
Merged

Better removal script#141
Zacgoose merged 1 commit intoCyberDrain:devfrom
Zacgoose:removal-script

Conversation

@Zacgoose
Copy link
Copy Markdown
Contributor

@Zacgoose Zacgoose commented Apr 8, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 8, 2026 14:22
@Zacgoose Zacgoose merged commit 72899b2 into CyberDrain:dev Apr 8, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -Recurse on the managed storage policy key.
  • Replace granular extension policy value deletion with Remove-Item -Recurse on the ExtensionSettings\<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.

Comment on lines +20 to +24
# 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"
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +36
# 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"
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
)

# Remove properties from managed storage key
# Remove all managed policy values and nested keys created for this extension.
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants