Skip to content

Commit 66757e5

Browse files
authored
Merge pull request #5 from ppfeister/dev
Optimizations and bugfixes
2 parents e850cbe + 854086d commit 66757e5

8 files changed

+92
-86
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ Clean Windows of as much bloatware and telemetry as possible without impeding no
66

77
Must be ran in an **elevated** PowerShell instance. **Reboot when complete.**
88
```powershell
9-
Set-ExecutionPolicy Unrestricted -Scope Process # Confirm with Y or A
9+
Set-ExecutionPolicy Bypass -Scope Process # Confirm with Y or A
1010
11-
# User will be presented with an interactive menu
12-
# If presented with a security warning, press R to continue (this may happen never, or a ton)
13-
. ./windex.ps1
11+
. ./windex.ps1 # User will be presented with an interactive menu
1412
```

modules/Autorun Tweaks.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ function runRegistryTweak {
1515
)
1616

1717
if ($script:UndoAll -and $tweakUri -like "*`(revert`)`.reg") {
18-
REG IMPORT `"$tweakUri`"
18+
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
19+
REG IMPORT `"$tweakUri`" 2>&1 | Out-Null
1920
}
2021
elseif (-not $script:UndoAll -and $tweakUri -notlike "*`(revert`)`.reg") {
21-
REG IMPORT `"$tweakUri`"
22+
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
23+
REG IMPORT `"$tweakUri`" 2>&1 | Out-Null
2224
}
2325
}
2426

2527
Get-ChildItem -Path "$(Split-Path $MyInvocation.MyCommand.Path -Parent)\..\tweaks\autorun\" | ForEach-Object {
2628
$tweakUri = $_.FullName
2729
$extension = (Get-Item $tweakUri).Extension
2830

31+
if ($extension -ne ".reg") {
32+
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
33+
}
34+
2935
Switch ($extension) {
3036
".ps1" { . "$tweakUri" -Undo:$script:UndoAll }
3137
".reg" { runRegistryTweak -tweakUri $tweakUri }

modules/Debloat AppX.ps1

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -60,88 +60,93 @@ $itemNames = loadManifest -ManifestUri "$ManifestDirectory\$ManifestCategory.txt
6060

6161
$PurgePackage = {
6262
param (
63-
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName,
64-
[Parameter(Position = 1, Mandatory = $false)] [int] $attempt = 0
63+
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName
6564
)
6665

67-
$maxAttempts = 4
68-
$appxOpCollisionErr ="Another operation on app packages (.appx) is in progress.`nWait for the current operation to complete and then retry the command. For more information, see the help."
66+
function PurgeBlock {
67+
param (
68+
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName,
69+
[Parameter(Position = 1, Mandatory = $false)] [int] $attempt = 0
70+
)
6971

70-
# REMOVING PACKAGES
71-
try {
72-
$installed = Get-AppxPackage -AllUsers -ErrorAction Stop | Select-Object PackageFullName,Name `
73-
| Where-Object Name -eq $PackageName `
74-
| Select-Object -ExpandProperty PackageFullName
75-
} catch {
76-
if ($_.Exception.Message -like $appxOpCollisionErr) {
77-
if ($attempt -lt $maxAttempts) {
78-
Start-Sleep -Seconds 5
79-
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
80-
} else {
81-
Write-Error "Failed to query installed AppX packages for $PackageName after $maxAttempts attempts."
82-
}
83-
} else {
84-
throw $_.Exception
85-
}
86-
}
72+
$maxAttempts = 4
73+
$appxOpCollisionErr ="Another operation on app packages (.appx) is in progress."
8774

88-
if ($installed) {
75+
# REMOVING PACKAGES
8976
try {
90-
Remove-AppxPackage -Verbose:$false -Package $installed -ErrorAction Stop
91-
Write-Verbose "Removed AppX package $PackageName."
77+
$installed = Get-AppxPackage -AllUsers -ErrorAction Stop | Select-Object PackageFullName,Name `
78+
| Where-Object Name -eq $PackageName `
79+
| Select-Object -ExpandProperty PackageFullName
9280
} catch {
93-
if ($_.Exception.Message -like $appxOpCollisionErr) {
81+
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
9482
if ($attempt -lt $maxAttempts) {
9583
Start-Sleep -Seconds 5
96-
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
84+
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
9785
} else {
98-
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
86+
Write-Error "Failed to query installed AppX packages for $PackageName after $maxAttempts attempts."
9987
}
10088
} else {
101-
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
89+
throw $_.Exception
10290
}
10391
}
104-
Clear-Variable installed
105-
}
106-
10792

108-
109-
# DEPROVISION
110-
try {
111-
$provisioned = Get-AppxProvisionedPackage -Online -Verbose:$false -ErrorAction Stop `
112-
| Where-Object DisplayName -eq $PackageName `
113-
| Select-Object -ExpandProperty PackageName
114-
} catch {
115-
if ($_.Exception.Message -like $appxOpCollisionErr) {
116-
if ($attempt -lt $maxAttempts) {
117-
Start-Sleep -Seconds 5
118-
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
119-
} else {
120-
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
93+
if ($installed) {
94+
try {
95+
Remove-AppxPackage -Verbose:$false -Package $installed -ErrorAction Stop
96+
Write-Verbose "Removed AppX package $PackageName."
97+
} catch {
98+
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
99+
if ($attempt -lt $maxAttempts) {
100+
Start-Sleep -Seconds 5
101+
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
102+
} else {
103+
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
104+
}
105+
} else {
106+
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
107+
}
121108
}
122-
} else {
123-
throw $_.Exception
109+
Clear-Variable installed
124110
}
125-
}
126111

127-
if ($provisioned) {
112+
# DEPROVISION
128113
try {
129-
Remove-AppxProvisionedPackage -Online -Verbose:$false -PackageName $provisioned -ErrorAction Stop | Out-Null
130-
Write-Verbose "Deprovisioned AppX package $PackageName."
114+
$provisioned = Get-AppxProvisionedPackage -Online -Verbose:$false -ErrorAction Stop `
115+
| Where-Object DisplayName -eq $PackageName `
116+
| Select-Object -ExpandProperty PackageName
131117
} catch {
132-
if ($_.Exception.Message -like $appxOpCollisionErr) {
118+
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
133119
if ($attempt -lt $maxAttempts) {
134120
Start-Sleep -Seconds 5
135-
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
121+
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
136122
} else {
137123
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
138124
}
139125
} else {
140-
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
126+
throw $_.Exception
127+
}
128+
}
129+
130+
if ($provisioned) {
131+
try {
132+
Remove-AppxProvisionedPackage -Online -Verbose:$false -PackageName $provisioned -ErrorAction Stop | Out-Null
133+
Write-Verbose "Deprovisioned AppX package $PackageName."
134+
} catch {
135+
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
136+
if ($attempt -lt $maxAttempts) {
137+
Start-Sleep -Seconds 5
138+
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
139+
} else {
140+
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
141+
}
142+
} else {
143+
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
144+
}
141145
}
146+
Clear-Variable provisioned
142147
}
143-
Clear-Variable provisioned
144148
}
149+
PurgeBlock -PackageName $PackageName
145150
}
146151

147152
$RemovalJobs = @()

tweaks/autorun/Declutter Start Menu.ps1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $userProfiles = Get-ChildItem "$env:SystemDrive\Users" `
3535
| Where-Object { $_.Name -ne "Public" } `
3636
| Where-Object { $_.Name -ne "Default" }
3737

38-
Write-Verbose "Users found for Start Menu override: $($userProfiles.Name -join ', ')."
38+
Write-Verbose "Users found for Start Menu override: $($userProfiles.Name -join ', ')"
3939

4040
##### Apply Template
4141

@@ -47,7 +47,7 @@ Import-StartLayout -LayoutPath "$layoutSourceUri" -MountPath "$env:SystemDrive\"
4747
# Applies template to each existing user
4848
foreach ($profile in $userProfiles) {
4949
$ntuserPath = $profile.FullName
50-
Write-Verbose "Copying Start Menu override to $($profile.Name)'s profile."
50+
Write-Verbose "Copying Start Menu override to $($profile.Name)"
5151
Copy-Item -Path "$layoutSourceUri" -Destination "$ntuserPath\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -Force
5252
}
5353

@@ -66,7 +66,7 @@ foreach ($profile in $userProfiles) {
6666
}
6767

6868
if (Test-Path "HKU\IdleUser\$regKey") {
69-
Remove-Item "registry::HKU\IdleUser\$regKey" -Force -Recurse
69+
Remove-Item "registry::HKU\IdleUser\$regKey" -Force -Recurse -Verbose:$true
7070
Write-Verbose "Registry key deleted to reset $($profile.Name)'s Start Menu cache."
7171
} else {
7272
Write-Verbose "Registry key not found for $($profile.Name). Their cache may not exist. Skipping."
@@ -80,8 +80,12 @@ $KnownSIDs = Get-ChildItem registry::HKEY_USERS\ `
8080

8181
foreach ($SID in $KnownSIDs) {
8282
try {
83+
Write-Verbose "Removing Start Layout cache from SID $(($SID -split '\\')[1])"
8384
Remove-Item "registry::$SID\$regKey" -Recurse -Force
8485
} catch {
85-
Write-Error "Failed to remove Start Layout cache key for $SID"
86+
Write-Error "Failed to remove Start Layout cache from $SID"
8687
}
87-
}
88+
}
89+
90+
Write-Verbose "Restarting Explorer to rebuild current user's Start Layout cache"
91+
Get-Process Explorer | Stop-Process

tweaks/autorun/Remove Ancient Capabilities.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ $packages = @(
3838

3939
if ($Undo) {
4040
ForEach ($package in $packages) {
41-
Add-WindowsCapability -Name $package -Online -ErrorAction Continue
41+
Add-WindowsCapability -Name $package -Online -ErrorAction Continue -Verbose:$false | Out-Null
4242
}
43-
return 0
43+
return
4444
}
4545

4646
ForEach ($package in $packages) {
47-
Remove-WindowsCapability -Name $package -Online -ErrorAction Continue
47+
Remove-WindowsCapability -Name $package -Online -ErrorAction Continue -Verbose:$false | Out-Null
4848
}
49-
return 0

tweaks/autorun/Remove Search Bar.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ foreach ($SID in $KnownSIDs) {
4242
#Set-ItemProperty -Path "registry::HKU\UserSkel\Software\Microsoft\Windows\CurrentVersion\Search" -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
4343
#REG UNLOAD HKU\UserSkel
4444

45-
Write-Host "Changes made to the active user will be reflected in the next session."
45+
Write-Verbose "Restarting Explorer to update the taskbar."
46+
Get-Process Explorer | Stop-Process

tweaks/optional/Remove Edge.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,22 @@ function RemoveWebView {
272272

273273
function UninstallAll {
274274
if ($removeEdge) {
275-
Write-Warning "Uninstalling Edge Chromium..."
275+
Write-Verbose "Uninstalling Edge Chromium..."
276276
RemoveEdgeChromium
277277
if (!($KeepAppX)) {
278-
Write-Warning "Uninstalling AppX Edge..."
278+
Write-Verbose "Uninstalling AppX Edge..."
279279
RemoveEdgeAppx
280-
} else {Write-Warning "AppX Edge is being left, there might be a stub..."}
280+
} else {Write-Verbose "AppX Edge is being left, there might be a stub..."}
281281
}
282282
if ($removeWebView) {
283-
Write-Warning "Uninstalling Edge WebView..."
283+
Write-Verbose "Uninstalling Edge WebView..."
284284
RemoveWebView
285285
}
286286
if ($removeEdge -and $removeWebView) {
287-
Write-Warning "Deleting Edge Update..."
287+
Write-Verbose "Deleting Edge Update..."
288288
DeleteEdgeUpdate
289289
}
290-
Write-Warning "Applying EdgeUpdate policies..."
290+
Write-Verbose "Applying EdgeUpdate policies..."
291291
BlockEdgeInstallandUpdates
292292
}
293293

@@ -305,7 +305,7 @@ function ReinstallWarning {
305305
}
306306

307307
function Completed {
308-
Write-Host "`nCompleted." -ForegroundColor Green
308+
#Write-Host "`nCompleted." -ForegroundColor Green
309309
if (!$Exit) {
310310
PauseNul "Press any key to exit... "
311311
}

windex.ps1

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ if ($options[$menuItem_MetroDebloat3P]) {
174174
. "$WindexRoot\modules\Debloat AppX.ps1" -ManifestDirectory "$WindexRoot\defs" -ManifestCategory "metro\thirdparty"
175175
}
176176

177-
if ($options[$menuItem_AutoApplyTweaks]) {
178-
. "$WindexRoot\modules\Autorun Tweaks.ps1"
179-
}
180-
181177
if ($options[$menuItem_RemoveEdge]) {
182178
. "$WindexRoot\tweaks\optional\Remove Edge.ps1" -UninstallAll -Exit -Verbose:$false
183179
}
@@ -186,11 +182,8 @@ if ($options[$menuItem_WingetDebloat]) {
186182
. "$WindexRoot\modules\Debloat AppInst.ps1" -ManifestDirectory "$WindexRoot\defs\winget" -ManifestCategory "generalized-by-name"
187183
}
188184

189-
$confirmation = Read-Host "Many changes won't be realized until the next session. Are you ready to log out? (Type 'yes' to confirm)"
190-
if ($confirmation -eq "yes") {
191-
shutdown.exe /l /f
192-
} else {
193-
Write-Host "Log out cancelled."
185+
if ($options[$menuItem_AutoApplyTweaks]) {
186+
. "$WindexRoot\modules\Autorun Tweaks.ps1"
194187
}
195188

196189
Get-Process Explorer | Stop-Process

0 commit comments

Comments
 (0)