Skip to content

Commit 68b69b2

Browse files
committed
Update AutopilotBranding.ps1
1 parent 4634435 commit 68b69b2

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

AutopilotBranding/AutopilotBranding.ps1

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#PSScriptInfo
2-
.VERSION 3.3.0
2+
.VERSION 3.3.1
33
.GUID 39efc9c5-7b51-4d1f-b650-0f3818e5327a
44
.AUTHOR Michael Niehaus
55
.COMPANYNAME
@@ -33,6 +33,7 @@ v3.1.0 - 2025-06-01 - Modified WinGet logic, switched to PowerShell for creating
3333
v3.2.0 - 2025-07-15 - Various fixes (start menu layout, apps, etc.)
3434
v3.2.1 - 2025-07-15 - Updated makeapps.cmd to use PowerShell 7
3535
v3.3.0 - 2025-09-20 - Added bookmark cleanup for Edge, Chrome. Fixed start menu config. Added Try/catch/finally. Added OOBE check.
36+
v3.3.1 - 2025-10-10 - Minor bug fixes
3637
#>
3738

3839
[CmdletBinding()]
@@ -399,29 +400,40 @@ try
399400

400401
# Step 11A: Disable Optional features
401402
if ($config.Config.DisableOptionalFeatures.Feature.Count -gt 0) {
402-
$EnabledOptionalFeatures = Get-WindowsOptionalFeature -Online | Where-Object { $_.State -eq "Enabled" }
403-
foreach ($EnabledFeature in $EnabledOptionalFeatures) {
404-
if ($config.Config.DisableOptionalFeatures.Feature -contains $EnabledFeature.FeatureName) {
405-
Log "Disabling Optional Feature: $($EnabledFeature.FeatureName)"
406-
try {
407-
Disable-WindowsOptionalFeature -Online -FeatureName $EnabledFeature.FeatureName -NoRestart | Out-Null
403+
try {
404+
$EnabledOptionalFeatures = Get-WindowsOptionalFeature -Online | Where-Object { $_.State -eq "Enabled" }
405+
foreach ($EnabledFeature in $EnabledOptionalFeatures) {
406+
if ($config.Config.DisableOptionalFeatures.Feature -contains $EnabledFeature.FeatureName) {
407+
Log "Disabling Optional Feature: $($EnabledFeature.FeatureName)"
408+
try {
409+
Disable-WindowsOptionalFeature -Online -FeatureName $EnabledFeature.FeatureName -NoRestart | Out-Null
410+
}
411+
catch {}
408412
}
409-
catch {}
410413
}
414+
}
415+
catch {
416+
Log "Unexpected error querying Windows optional features: $_"
411417
}
412418
}
413419

414420
# Step 11B: Remove Windows Capabilities
415421
if ($config.Config.RemoveCapability.Capability.Count -gt 0) {
416-
$InstalledCapabilities = Get-WindowsCapability -Online | Where-Object { $_.State -eq "Installed" }
417-
foreach ($InstalledCapability in $InstalledCapabilities) {
418-
if ($config.Config.RemoveCapability.Capability -contains $InstalledCapability.Name.Split("~")[0]) {
419-
Log "Removing Windows Capability: $($InstalledCapability.Name)"
420-
try {
421-
Remove-WindowsCapability -Online -Name $InstalledCapability.Name | Out-Null
422+
try {
423+
$InstalledCapabilities = Get-WindowsCapability -Online | Where-Object { $_.State -eq "Installed" }
424+
foreach ($InstalledCapability in $InstalledCapabilities) {
425+
if ($config.Config.RemoveCapability.Capability -contains $InstalledCapability.Name.Split("~")[0]) {
426+
Log "Removing Windows Capability: $($InstalledCapability.Name)"
427+
try {
428+
Remove-WindowsCapability -Online -Name $InstalledCapability.Name | Out-Null
429+
}
430+
catch {
431+
Log " Unable to remove Windows capability: $_"
432+
}
422433
}
423-
catch {}
424434
}
435+
} catch {
436+
Log "Unexpected error querying Windows capabilities: $_"
425437
}
426438
}
427439

@@ -435,7 +447,9 @@ try
435447
Log " Feature $_ was installed but requires a restart"
436448
}
437449
}
438-
catch {}
450+
catch {
451+
Log " Unable to add Windows capability: $_"
452+
}
439453
}
440454
}
441455

@@ -563,7 +577,7 @@ try
563577
{
564578
MkDir $dest -Force | Out-Null
565579
}
566-
Copy-Item ".\initial_preferences" "$dest\" -Force
580+
Copy-Item "$PSScriptRoot\initial_preferences" "$dest\" -Force
567581
if (Test-Path "C:\Users\Public\Desktop\Google Chrome.lnk") {
568582
Log "Removing Chrome desktop shortcut"
569583
Remove-Item "C:\Users\Public\Desktop\Google Chrome.lnk" -Force

0 commit comments

Comments
 (0)