Skip to content

Commit 625c179

Browse files
committed
Add boolean settings to top of Edge scripts
Move all configurable options to dedicated SETTINGS section after Set-StrictMode per framework guidelines. Each feature can now be individually toggled with $true/$false.
1 parent 4986a0b commit 625c179

2 files changed

Lines changed: 335 additions & 183 deletions

File tree

scripts/edge_set_chrome_default_user.ps1

Lines changed: 126 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $ErrorActionPreference = 'Stop'
77
███████╗██║██║ ╚═╝ ██║███████╗██║ ██║██║ ██║╚███╔███╔╝██║ ██╗
88
╚══════╝╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝ ╚═╝
99
================================================================================
10-
SCRIPT : Edge Set Chrome Default v1.0.0
10+
SCRIPT : Edge Set Chrome Default v1.1.0
1111
AUTHOR : Limehawk.io
1212
DATE : December 2024
1313
USAGE : .\edge_set_chrome_default_user.ps1
@@ -32,16 +32,24 @@ $ErrorActionPreference = 'Stop'
3232
3333
REQUIRED INPUTS
3434
35-
All inputs are hardcoded in the script body:
36-
- No configurable inputs required
35+
All inputs are hardcoded in the script body (booleans, $true/$false):
36+
37+
Associations:
38+
- $setDefaultHttp: Set Chrome as default for http:// links
39+
- $setDefaultHttps: Set Chrome as default for https:// links
40+
- $setDefaultHtm: Set Chrome as default for .htm files
41+
- $setDefaultHtml: Set Chrome as default for .html files
42+
43+
Maintenance:
44+
- $cleanUserStartup: Remove Edge from user's startup programs
45+
46+
Tool Configuration:
47+
- $setUserFtaUrl: URL to download SetUserFTA (change for internal hosting)
3748
3849
SETTINGS
3950
40-
This script sets Chrome as default for:
41-
- http:// protocol (web links)
42-
- https:// protocol (secure web links)
43-
- .htm files
44-
- .html files
51+
All options default to $true. The SetUserFTA URL points to Microsoft's
52+
official GitHub release. Change it if you host the tool internally.
4553
4654
BEHAVIOR
4755
@@ -108,11 +116,28 @@ $ErrorActionPreference = 'Stop'
108116
--------------------------------------------------------------------------------
109117
CHANGELOG
110118
--------------------------------------------------------------------------------
119+
2024-12-27 v1.1.0 Added boolean settings at top for each feature
111120
2024-12-27 v1.0.0 Initial release - split from combined script
112121
================================================================================
113122
#>
114123
Set-StrictMode -Version Latest
115124

125+
# ============================================================================
126+
# SETTINGS - Set to $false to skip specific associations
127+
# ============================================================================
128+
129+
# Associations - which file types/protocols to set Chrome as default
130+
$setDefaultHttp = $true # Set Chrome as default for http:// links
131+
$setDefaultHttps = $true # Set Chrome as default for https:// links
132+
$setDefaultHtm = $true # Set Chrome as default for .htm files
133+
$setDefaultHtml = $true # Set Chrome as default for .html files
134+
135+
# Maintenance
136+
$cleanUserStartup = $true # Remove Edge from user's startup programs
137+
138+
# Tool Configuration - change URL if hosting SetUserFTA internally
139+
$setUserFtaUrl = 'https://github.com/AzureAD/SetUserFTA/releases/download/v1.0.0/SetUserFTA.exe'
140+
116141
# ============================================================================
117142
# STATE VARIABLES
118143
# ============================================================================
@@ -188,7 +213,6 @@ Write-Host "[ SETUP SETUSERFTA ]"
188213
Write-Host "--------------------------------------------------------------"
189214

190215
$setUserFtaPath = "$env:TEMP\SetUserFTA.exe"
191-
$setUserFtaUrl = "https://github.com/AzureAD/SetUserFTA/releases/download/v1.0.0/SetUserFTA.exe"
192216

193217
try {
194218
if (-not (Test-Path $setUserFtaPath)) {
@@ -226,58 +250,119 @@ Write-Host "[ SET CHROME DEFAULT ]"
226250
Write-Host "--------------------------------------------------------------"
227251

228252
$chromeProgId = "ChromeHTML"
229-
$associations = @(
230-
@{ Type = "http"; Desc = "http" },
231-
@{ Type = "https"; Desc = "https" },
232-
@{ Type = ".htm"; Desc = ".htm" },
233-
@{ Type = ".html"; Desc = ".html" }
234-
)
253+
$totalAssociations = 0
235254

236-
foreach ($assoc in $associations) {
255+
if ($setDefaultHttp) {
256+
$totalAssociations++
237257
try {
238-
$result = & $setUserFtaPath $assoc.Type $chromeProgId 2>&1
258+
$result = & $setUserFtaPath "http" $chromeProgId 2>&1
239259
if ($LASTEXITCODE -eq 0) {
240-
Write-Host "Set Chrome as default for $($assoc.Desc)"
260+
Write-Host "Set Chrome as default for http"
241261
$defaultsSet++
242262
} else {
243-
Write-Host "Failed to set $($assoc.Desc): $result"
263+
Write-Host "Failed to set http: $result"
244264
$errorOccurred = $true
245265
if ($errorText.Length -gt 0) { $errorText += "`n" }
246-
$errorText += "- Could not set $($assoc.Desc)"
266+
$errorText += "- Could not set http"
247267
}
248268
} catch {
249-
Write-Host "Error setting $($assoc.Desc): $($_.Exception.Message)"
269+
Write-Host "Error setting http: $($_.Exception.Message)"
250270
$errorOccurred = $true
251271
if ($errorText.Length -gt 0) { $errorText += "`n" }
252-
$errorText += "- Exception on $($assoc.Desc)"
272+
$errorText += "- Exception on http"
273+
}
274+
}
275+
276+
if ($setDefaultHttps) {
277+
$totalAssociations++
278+
try {
279+
$result = & $setUserFtaPath "https" $chromeProgId 2>&1
280+
if ($LASTEXITCODE -eq 0) {
281+
Write-Host "Set Chrome as default for https"
282+
$defaultsSet++
283+
} else {
284+
Write-Host "Failed to set https: $result"
285+
$errorOccurred = $true
286+
if ($errorText.Length -gt 0) { $errorText += "`n" }
287+
$errorText += "- Could not set https"
288+
}
289+
} catch {
290+
Write-Host "Error setting https: $($_.Exception.Message)"
291+
$errorOccurred = $true
292+
if ($errorText.Length -gt 0) { $errorText += "`n" }
293+
$errorText += "- Exception on https"
294+
}
295+
}
296+
297+
if ($setDefaultHtm) {
298+
$totalAssociations++
299+
try {
300+
$result = & $setUserFtaPath ".htm" $chromeProgId 2>&1
301+
if ($LASTEXITCODE -eq 0) {
302+
Write-Host "Set Chrome as default for .htm"
303+
$defaultsSet++
304+
} else {
305+
Write-Host "Failed to set .htm: $result"
306+
$errorOccurred = $true
307+
if ($errorText.Length -gt 0) { $errorText += "`n" }
308+
$errorText += "- Could not set .htm"
309+
}
310+
} catch {
311+
Write-Host "Error setting .htm: $($_.Exception.Message)"
312+
$errorOccurred = $true
313+
if ($errorText.Length -gt 0) { $errorText += "`n" }
314+
$errorText += "- Exception on .htm"
315+
}
316+
}
317+
318+
if ($setDefaultHtml) {
319+
$totalAssociations++
320+
try {
321+
$result = & $setUserFtaPath ".html" $chromeProgId 2>&1
322+
if ($LASTEXITCODE -eq 0) {
323+
Write-Host "Set Chrome as default for .html"
324+
$defaultsSet++
325+
} else {
326+
Write-Host "Failed to set .html: $result"
327+
$errorOccurred = $true
328+
if ($errorText.Length -gt 0) { $errorText += "`n" }
329+
$errorText += "- Could not set .html"
330+
}
331+
} catch {
332+
Write-Host "Error setting .html: $($_.Exception.Message)"
333+
$errorOccurred = $true
334+
if ($errorText.Length -gt 0) { $errorText += "`n" }
335+
$errorText += "- Exception on .html"
253336
}
254337
}
255338

256339
# ============================================================================
257340
# CLEANUP USER EDGE STARTUP
258341
# ============================================================================
259-
Write-Host ""
260-
Write-Host "[ USER CLEANUP ]"
261-
Write-Host "--------------------------------------------------------------"
342+
if ($cleanUserStartup) {
343+
Write-Host ""
344+
Write-Host "[ USER CLEANUP ]"
345+
Write-Host "--------------------------------------------------------------"
262346

263-
try {
264-
$userRunPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
265-
if (Test-Path $userRunPath) {
266-
$properties = Get-ItemProperty -Path $userRunPath -ErrorAction SilentlyContinue
267-
if ($properties) {
268-
$edgeEntries = $properties.PSObject.Properties | Where-Object { $_.Name -like "*Edge*" -or $_.Name -like "*MicrosoftEdge*" }
269-
if ($edgeEntries) {
270-
foreach ($entry in $edgeEntries) {
271-
Remove-ItemProperty -Path $userRunPath -Name $entry.Name -Force -ErrorAction SilentlyContinue
272-
Write-Host "Removed user startup : $($entry.Name)"
347+
try {
348+
$userRunPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
349+
if (Test-Path $userRunPath) {
350+
$properties = Get-ItemProperty -Path $userRunPath -ErrorAction SilentlyContinue
351+
if ($properties) {
352+
$edgeEntries = $properties.PSObject.Properties | Where-Object { $_.Name -like "*Edge*" -or $_.Name -like "*MicrosoftEdge*" }
353+
if ($edgeEntries) {
354+
foreach ($entry in $edgeEntries) {
355+
Remove-ItemProperty -Path $userRunPath -Name $entry.Name -Force -ErrorAction SilentlyContinue
356+
Write-Host "Removed user startup : $($entry.Name)"
357+
}
358+
} else {
359+
Write-Host "No Edge user startup entries"
273360
}
274-
} else {
275-
Write-Host "No Edge user startup entries"
276361
}
277362
}
363+
} catch {
364+
Write-Host "Cleanup skipped: $($_.Exception.Message)"
278365
}
279-
} catch {
280-
Write-Host "Cleanup skipped: $($_.Exception.Message)"
281366
}
282367

283368
# ============================================================================
@@ -303,13 +388,13 @@ if ($defaultsSet -eq 0) {
303388

304389
if ($errorOccurred) {
305390
Write-Host "Result : PARTIAL SUCCESS"
306-
Write-Host "Defaults set : $defaultsSet of 4"
391+
Write-Host "Defaults set : $defaultsSet of $totalAssociations"
307392
Write-Host ""
308393
Write-Host "Warnings:"
309394
Write-Host $errorText
310395
} else {
311396
Write-Host "Result : SUCCESS"
312-
Write-Host "Defaults set : $defaultsSet of 4"
397+
Write-Host "Defaults set : $defaultsSet of $totalAssociations"
313398
Write-Host ""
314399
Write-Host "Chrome is now the default browser for this user"
315400
}

0 commit comments

Comments
 (0)