Skip to content

Commit 72899b2

Browse files
authored
Merge pull request #141 from Zacgoose/removal-script
Better removal script
2 parents 390af47 + 78f1a5b commit 72899b2

1 file changed

Lines changed: 12 additions & 139 deletions

File tree

enterprise/Remove-Windows-Chrome-and-Edge.ps1

Lines changed: 12 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -17,155 +17,28 @@ function Remove-ExtensionSettings {
1717
[string]$ExtensionSettingsKey
1818
)
1919

20-
# Remove properties from managed storage key
20+
# Remove all managed policy values and nested keys created for this extension.
2121
if (Test-Path $ManagedStorageKey) {
22-
$propertiesToRemove = @(
23-
"showNotifications",
24-
"enableValidPageBadge",
25-
"enablePageBlocking",
26-
"enableCippReporting",
27-
"cippServerUrl",
28-
"cippTenantId",
29-
"customRulesUrl",
30-
"updateInterval",
31-
"enableDebugLogging"
32-
)
33-
34-
foreach ($property in $propertiesToRemove) {
35-
if (Get-ItemProperty -Path $ManagedStorageKey -Name $property -ErrorAction SilentlyContinue) {
36-
Remove-ItemProperty -Path $ManagedStorageKey -Name $property -Force -ErrorAction SilentlyContinue
37-
Write-Host "Removed property: $property from $ManagedStorageKey"
38-
}
39-
}
40-
41-
# Remove URL allowlist subkey and all its properties
42-
$urlAllowlistKey = "$ManagedStorageKey\urlAllowlist"
43-
if (Test-Path $urlAllowlistKey) {
44-
# Remove all numbered properties (1, 2, 3, etc.)
45-
$properties = Get-ItemProperty -Path $urlAllowlistKey -ErrorAction SilentlyContinue
46-
if ($properties) {
47-
$properties.PSObject.Properties | Where-Object { $_.Name -match '^\d+$' } | ForEach-Object {
48-
Remove-ItemProperty -Path $urlAllowlistKey -Name $_.Name -Force -ErrorAction SilentlyContinue
49-
Write-Host "Removed URL allowlist property: $($_.Name) from $urlAllowlistKey"
50-
}
51-
}
52-
# Remove the urlAllowlist subkey if it's empty
53-
try {
54-
Remove-Item -Path $urlAllowlistKey -Force -ErrorAction SilentlyContinue
55-
Write-Host "Removed URL allowlist subkey: $urlAllowlistKey"
56-
} catch {
57-
# Key may not be empty or may have been removed already
58-
}
59-
}
60-
61-
# Remove generic webhook subkey and event properties
62-
$genericWebhookKey = "$ManagedStorageKey\genericWebhook"
63-
if (Test-Path $genericWebhookKey) {
64-
$webhookEventsKey = "$genericWebhookKey\events"
65-
if (Test-Path $webhookEventsKey) {
66-
$eventProperties = Get-ItemProperty -Path $webhookEventsKey -ErrorAction SilentlyContinue
67-
if ($eventProperties) {
68-
$eventProperties.PSObject.Properties | Where-Object { $_.Name -match '^\d+$' } | ForEach-Object {
69-
Remove-ItemProperty -Path $webhookEventsKey -Name $_.Name -Force -ErrorAction SilentlyContinue
70-
Write-Host "Removed webhook event property: $($_.Name) from $webhookEventsKey"
71-
}
72-
}
73-
try {
74-
Remove-Item -Path $webhookEventsKey -Force -ErrorAction SilentlyContinue
75-
Write-Host "Removed webhook events subkey: $webhookEventsKey"
76-
} catch {
77-
# Key may not be empty or may have been removed already
78-
}
79-
}
80-
81-
foreach ($property in @("enabled", "url")) {
82-
if (Get-ItemProperty -Path $genericWebhookKey -Name $property -ErrorAction SilentlyContinue) {
83-
Remove-ItemProperty -Path $genericWebhookKey -Name $property -Force -ErrorAction SilentlyContinue
84-
Write-Host "Removed generic webhook property: $property from $genericWebhookKey"
85-
}
86-
}
87-
88-
try {
89-
Remove-Item -Path $genericWebhookKey -Force -ErrorAction SilentlyContinue
90-
Write-Host "Removed generic webhook subkey: $genericWebhookKey"
91-
} catch {
92-
# Key may not be empty or may have been removed already
93-
}
94-
}
95-
96-
# Remove custom branding subkey and all its properties
97-
$customBrandingKey = "$ManagedStorageKey\customBranding"
98-
if (Test-Path $customBrandingKey) {
99-
$brandingPropertiesToRemove = @(
100-
"companyName",
101-
"productName",
102-
"supportEmail",
103-
"supportUrl",
104-
"privacyPolicyUrl",
105-
"aboutUrl",
106-
"primaryColor",
107-
"logoUrl"
108-
)
109-
110-
foreach ($property in $brandingPropertiesToRemove) {
111-
if (Get-ItemProperty -Path $customBrandingKey -Name $property -ErrorAction SilentlyContinue) {
112-
Remove-ItemProperty -Path $customBrandingKey -Name $property -Force -ErrorAction SilentlyContinue
113-
Write-Host "Removed custom branding property: $property from $customBrandingKey"
114-
}
115-
}
116-
117-
# Remove the customBranding subkey if it's empty
118-
try {
119-
Remove-Item -Path $customBrandingKey -Force -ErrorAction SilentlyContinue
120-
Write-Host "Removed custom branding subkey: $customBrandingKey"
121-
} catch {
122-
# Key may not be empty or may have been removed already
123-
}
124-
}
125-
126-
# Remove the managed storage key if it's empty
12722
try {
128-
$remainingProperties = Get-ItemProperty -Path $ManagedStorageKey -ErrorAction SilentlyContinue
129-
if ($remainingProperties -and $remainingProperties.PSObject.Properties.Count -eq 0) {
130-
Remove-Item -Path $ManagedStorageKey -Force -ErrorAction SilentlyContinue
131-
Write-Host "Removed managed storage key: $ManagedStorageKey"
132-
}
23+
Remove-Item -Path $ManagedStorageKey -Recurse -Force -ErrorAction Stop
24+
Write-Host "Removed managed storage key: $ManagedStorageKey"
13325
} catch {
134-
# Key may not be empty or may have been removed already
26+
Write-Warning "Failed to remove managed storage key: $ManagedStorageKey. Error: $($_.Exception.Message)"
13527
}
28+
} else {
29+
Write-Host "Managed storage key not found (already removed): $ManagedStorageKey"
13630
}
13731

138-
# Remove properties from extension settings key
32+
# Remove extension install/settings key for this extension.
13933
if (Test-Path $ExtensionSettingsKey) {
140-
$extensionPropertiesToRemove = @(
141-
"installation_mode",
142-
"update_url"
143-
)
144-
145-
# Add browser-specific toolbar properties
146-
if ($ExtensionId -eq $edgeExtensionId) {
147-
$extensionPropertiesToRemove += "toolbar_state"
148-
} elseif ($ExtensionId -eq $chromeExtensionId) {
149-
$extensionPropertiesToRemove += "toolbar_pin"
150-
}
151-
152-
foreach ($property in $extensionPropertiesToRemove) {
153-
if (Get-ItemProperty -Path $ExtensionSettingsKey -Name $property -ErrorAction SilentlyContinue) {
154-
Remove-ItemProperty -Path $ExtensionSettingsKey -Name $property -Force -ErrorAction SilentlyContinue
155-
Write-Host "Removed extension setting property: $property from $ExtensionSettingsKey"
156-
}
157-
}
158-
159-
# Remove the extension settings key if it's empty
16034
try {
161-
$remainingProperties = Get-ItemProperty -Path $ExtensionSettingsKey -ErrorAction SilentlyContinue
162-
if ($remainingProperties -and $remainingProperties.PSObject.Properties.Count -eq 0) {
163-
Remove-Item -Path $ExtensionSettingsKey -Force -ErrorAction SilentlyContinue
164-
Write-Host "Removed extension settings key: $ExtensionSettingsKey"
165-
}
35+
Remove-Item -Path $ExtensionSettingsKey -Recurse -Force -ErrorAction Stop
36+
Write-Host "Removed extension settings key: $ExtensionSettingsKey"
16637
} catch {
167-
# Key may not be empty or may have been removed already
38+
Write-Warning "Failed to remove extension settings key: $ExtensionSettingsKey. Error: $($_.Exception.Message)"
16839
}
40+
} else {
41+
Write-Host "Extension settings key not found (already removed): $ExtensionSettingsKey"
16942
}
17043

17144
Write-Host "Completed removal of extension settings for $ExtensionId"

0 commit comments

Comments
 (0)