Skip to content

Commit

Permalink
Merge pull request #5 from ppfeister/dev
Browse files Browse the repository at this point in the history
Optimizations and bugfixes
  • Loading branch information
ppfeister committed Feb 9, 2024
2 parents e850cbe + 854086d commit 66757e5
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 86 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ Clean Windows of as much bloatware and telemetry as possible without impeding no

Must be ran in an **elevated** PowerShell instance. **Reboot when complete.**
```powershell
Set-ExecutionPolicy Unrestricted -Scope Process # Confirm with Y or A
Set-ExecutionPolicy Bypass -Scope Process # Confirm with Y or A
# User will be presented with an interactive menu
# If presented with a security warning, press R to continue (this may happen never, or a ton)
. ./windex.ps1
. ./windex.ps1 # User will be presented with an interactive menu
```
10 changes: 8 additions & 2 deletions modules/Autorun Tweaks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ function runRegistryTweak {
)

if ($script:UndoAll -and $tweakUri -like "*`(revert`)`.reg") {
REG IMPORT `"$tweakUri`"
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
REG IMPORT `"$tweakUri`" 2>&1 | Out-Null
}
elseif (-not $script:UndoAll -and $tweakUri -notlike "*`(revert`)`.reg") {
REG IMPORT `"$tweakUri`"
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
REG IMPORT `"$tweakUri`" 2>&1 | Out-Null
}
}

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

if ($extension -ne ".reg") {
Write-Verbose "Found tweak $((Get-Item $tweakUri).BaseName)"
}

Switch ($extension) {
".ps1" { . "$tweakUri" -Undo:$script:UndoAll }
".reg" { runRegistryTweak -tweakUri $tweakUri }
Expand Down
113 changes: 59 additions & 54 deletions modules/Debloat AppX.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,88 +60,93 @@ $itemNames = loadManifest -ManifestUri "$ManifestDirectory\$ManifestCategory.txt

$PurgePackage = {
param (
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName,
[Parameter(Position = 1, Mandatory = $false)] [int] $attempt = 0
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName
)

$maxAttempts = 4
$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."
function PurgeBlock {
param (
[Parameter(Position = 0, Mandatory = $true)] [string] $PackageName,
[Parameter(Position = 1, Mandatory = $false)] [int] $attempt = 0
)

# REMOVING PACKAGES
try {
$installed = Get-AppxPackage -AllUsers -ErrorAction Stop | Select-Object PackageFullName,Name `
| Where-Object Name -eq $PackageName `
| Select-Object -ExpandProperty PackageFullName
} catch {
if ($_.Exception.Message -like $appxOpCollisionErr) {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query installed AppX packages for $PackageName after $maxAttempts attempts."
}
} else {
throw $_.Exception
}
}
$maxAttempts = 4
$appxOpCollisionErr ="Another operation on app packages (.appx) is in progress."

if ($installed) {
# REMOVING PACKAGES
try {
Remove-AppxPackage -Verbose:$false -Package $installed -ErrorAction Stop
Write-Verbose "Removed AppX package $PackageName."
$installed = Get-AppxPackage -AllUsers -ErrorAction Stop | Select-Object PackageFullName,Name `
| Where-Object Name -eq $PackageName `
| Select-Object -ExpandProperty PackageFullName
} catch {
if ($_.Exception.Message -like $appxOpCollisionErr) {
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
Write-Error "Failed to query installed AppX packages for $PackageName after $maxAttempts attempts."
}
} else {
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
throw $_.Exception
}
}
Clear-Variable installed
}



# DEPROVISION
try {
$provisioned = Get-AppxProvisionedPackage -Online -Verbose:$false -ErrorAction Stop `
| Where-Object DisplayName -eq $PackageName `
| Select-Object -ExpandProperty PackageName
} catch {
if ($_.Exception.Message -like $appxOpCollisionErr) {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
if ($installed) {
try {
Remove-AppxPackage -Verbose:$false -Package $installed -ErrorAction Stop
Write-Verbose "Removed AppX package $PackageName."
} catch {
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
}
} else {
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
}
}
} else {
throw $_.Exception
Clear-Variable installed
}
}

if ($provisioned) {
# DEPROVISION
try {
Remove-AppxProvisionedPackage -Online -Verbose:$false -PackageName $provisioned -ErrorAction Stop | Out-Null
Write-Verbose "Deprovisioned AppX package $PackageName."
$provisioned = Get-AppxProvisionedPackage -Online -Verbose:$false -ErrorAction Stop `
| Where-Object DisplayName -eq $PackageName `
| Select-Object -ExpandProperty PackageName
} catch {
if ($_.Exception.Message -like $appxOpCollisionErr) {
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
return & $PurgePackage -PackageName $PackageName -attempt ($attempt + 1)
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
}
} else {
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
throw $_.Exception
}
}

if ($provisioned) {
try {
Remove-AppxProvisionedPackage -Online -Verbose:$false -PackageName $provisioned -ErrorAction Stop | Out-Null
Write-Verbose "Deprovisioned AppX package $PackageName."
} catch {
if ($_.Exception.Message -like "*$appxOpCollisionErr*") {
if ($attempt -lt $maxAttempts) {
Start-Sleep -Seconds 5
PurgeBlock -PackageName $PackageName -attempt ($attempt + 1)
} else {
Write-Error "Failed to query provisioned AppX packages for $PackageName after $maxAttempts attempts."
}
} else {
Write-Error "Failed to deprovision AppX package $PackageName.`n$_.Exception.Message"
}
}
Clear-Variable provisioned
}
Clear-Variable provisioned
}
PurgeBlock -PackageName $PackageName
}

$RemovalJobs = @()
Expand Down
14 changes: 9 additions & 5 deletions tweaks/autorun/Declutter Start Menu.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $userProfiles = Get-ChildItem "$env:SystemDrive\Users" `
| Where-Object { $_.Name -ne "Public" } `
| Where-Object { $_.Name -ne "Default" }

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

##### Apply Template

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

Expand All @@ -66,7 +66,7 @@ foreach ($profile in $userProfiles) {
}

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

foreach ($SID in $KnownSIDs) {
try {
Write-Verbose "Removing Start Layout cache from SID $(($SID -split '\\')[1])"
Remove-Item "registry::$SID\$regKey" -Recurse -Force
} catch {
Write-Error "Failed to remove Start Layout cache key for $SID"
Write-Error "Failed to remove Start Layout cache from $SID"
}
}
}

Write-Verbose "Restarting Explorer to rebuild current user's Start Layout cache"
Get-Process Explorer | Stop-Process
7 changes: 3 additions & 4 deletions tweaks/autorun/Remove Ancient Capabilities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ $packages = @(

if ($Undo) {
ForEach ($package in $packages) {
Add-WindowsCapability -Name $package -Online -ErrorAction Continue
Add-WindowsCapability -Name $package -Online -ErrorAction Continue -Verbose:$false | Out-Null
}
return 0
return
}

ForEach ($package in $packages) {
Remove-WindowsCapability -Name $package -Online -ErrorAction Continue
Remove-WindowsCapability -Name $package -Online -ErrorAction Continue -Verbose:$false | Out-Null
}
return 0
3 changes: 2 additions & 1 deletion tweaks/autorun/Remove Search Bar.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ foreach ($SID in $KnownSIDs) {
#Set-ItemProperty -Path "registry::HKU\UserSkel\Software\Microsoft\Windows\CurrentVersion\Search" -Name SearchBoxTaskbarMode -Value 0 -Type DWord -Force
#REG UNLOAD HKU\UserSkel

Write-Host "Changes made to the active user will be reflected in the next session."
Write-Verbose "Restarting Explorer to update the taskbar."
Get-Process Explorer | Stop-Process
14 changes: 7 additions & 7 deletions tweaks/optional/Remove Edge.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,22 @@ function RemoveWebView {

function UninstallAll {
if ($removeEdge) {
Write-Warning "Uninstalling Edge Chromium..."
Write-Verbose "Uninstalling Edge Chromium..."
RemoveEdgeChromium
if (!($KeepAppX)) {
Write-Warning "Uninstalling AppX Edge..."
Write-Verbose "Uninstalling AppX Edge..."
RemoveEdgeAppx
} else {Write-Warning "AppX Edge is being left, there might be a stub..."}
} else {Write-Verbose "AppX Edge is being left, there might be a stub..."}
}
if ($removeWebView) {
Write-Warning "Uninstalling Edge WebView..."
Write-Verbose "Uninstalling Edge WebView..."
RemoveWebView
}
if ($removeEdge -and $removeWebView) {
Write-Warning "Deleting Edge Update..."
Write-Verbose "Deleting Edge Update..."
DeleteEdgeUpdate
}
Write-Warning "Applying EdgeUpdate policies..."
Write-Verbose "Applying EdgeUpdate policies..."
BlockEdgeInstallandUpdates
}

Expand All @@ -305,7 +305,7 @@ function ReinstallWarning {
}

function Completed {
Write-Host "`nCompleted." -ForegroundColor Green
#Write-Host "`nCompleted." -ForegroundColor Green
if (!$Exit) {
PauseNul "Press any key to exit... "
}
Expand Down
11 changes: 2 additions & 9 deletions windex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ if ($options[$menuItem_MetroDebloat3P]) {
. "$WindexRoot\modules\Debloat AppX.ps1" -ManifestDirectory "$WindexRoot\defs" -ManifestCategory "metro\thirdparty"
}

if ($options[$menuItem_AutoApplyTweaks]) {
. "$WindexRoot\modules\Autorun Tweaks.ps1"
}

if ($options[$menuItem_RemoveEdge]) {
. "$WindexRoot\tweaks\optional\Remove Edge.ps1" -UninstallAll -Exit -Verbose:$false
}
Expand All @@ -186,11 +182,8 @@ if ($options[$menuItem_WingetDebloat]) {
. "$WindexRoot\modules\Debloat AppInst.ps1" -ManifestDirectory "$WindexRoot\defs\winget" -ManifestCategory "generalized-by-name"
}

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

Get-Process Explorer | Stop-Process

0 comments on commit 66757e5

Please sign in to comment.