CustomAppsList file now supports comments (#103)

Additionally added Microsoft.BingSearch to Appslist.txt
This commit is contained in:
Raphire
2024-08-02 13:31:20 +02:00
parent 69590c55e2
commit dbab8e3812
2 changed files with 41 additions and 73 deletions

View File

@@ -95,6 +95,7 @@ XING
# The apps below this line will NOT be uninstalled. If you wish to REMOVE any of the apps below # The apps below this line will NOT be uninstalled. If you wish to REMOVE any of the apps below
# simply remove the # character in front of the specific app. # simply remove the # character in front of the specific app.
# #
#Microsoft.BingSearch # Web Search from Microsoft Bing (Integrates into Windows Search)
#Microsoft.Edge # Edge browser (Can only be uninstalled in European Economic Area) #Microsoft.Edge # Edge browser (Can only be uninstalled in European Economic Area)
#Microsoft.GetHelp # Required for some Windows 11 Troubleshooters #Microsoft.GetHelp # Required for some Windows 11 Troubleshooters
#Microsoft.MSPaint # Paint 3D #Microsoft.MSPaint # Paint 3D

View File

@@ -297,35 +297,29 @@ function ShowAppSelectionForm {
} }
# Reads list of apps from file and removes them for all user accounts and from the OS image. # Returns list of apps from the specified file, it trims the app names and removes any comments
function RemoveAppsFromFile { function ReadAppslistFromFile {
param ( param (
$appsFilePath $appsFilePath
) )
$appsList = @() $appsList = @()
Write-Output "> Removing default selection of apps..."
# Get list of apps from file at the path provided, and remove them one by one # Get list of apps from file at the path provided, and remove them one by one
Foreach ($app in (Get-Content -Path $appsFilePath | Where-Object { $_ -notmatch '^#.*' -and $_ -notmatch '^\s*$' } )) { Foreach ($app in (Get-Content -Path $appsFilePath | Where-Object { $_ -notmatch '^#.*' -and $_ -notmatch '^\s*$' } )) {
# Remove any spaces before and after the Appname
$app = $app.Trim()
# Remove any comments from the Appname # Remove any comments from the Appname
if (-not ($app.IndexOf('#') -eq -1)) { if (-not ($app.IndexOf('#') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf('#')) $app = $app.Substring(0, $app.IndexOf('#'))
} }
# Remove any remaining spaces from the Appname
if (-not ($app.IndexOf(' ') -eq -1)) { # Remove any spaces before and after the Appname
$app = $app.Substring(0, $app.IndexOf(' ')) $app = $app.Trim()
}
$appString = $app.Trim('*') $appString = $app.Trim('*')
$appsList += $appString $appsList += $appString
} }
RemoveApps $appsList return $appsList
} }
@@ -341,14 +335,14 @@ function RemoveApps {
if (($app -eq "Microsoft.OneDrive") -or ($app -eq "Microsoft.Edge")) { if (($app -eq "Microsoft.OneDrive") -or ($app -eq "Microsoft.Edge")) {
# Use winget to remove OneDrive and Edge # Use winget to remove OneDrive and Edge
if ($global:wingetInstalled -eq $false) { if ($global:wingetInstalled -eq $false) {
Write-Host "WinGet is either not installed or is outdated, so $app could not be removed" -ForegroundColor Red Write-Host "Error: WinGet is either not installed or is outdated, $app could not be removed" -ForegroundColor Red
} }
else { else {
# Uninstall app via winget # Uninstall app via winget
Strip-Progress -ScriptBlock { winget uninstall --accept-source-agreements --disable-interactivity --id $app } | Tee-Object -Variable wingetOutput Strip-Progress -ScriptBlock { winget uninstall --accept-source-agreements --disable-interactivity --id $app } | Tee-Object -Variable wingetOutput
If (($app -eq "Microsoft.Edge") -and (Select-String -InputObject $wingetOutput -Pattern "93")) { If (($app -eq "Microsoft.Edge") -and (Select-String -InputObject $wingetOutput -Pattern "93")) {
Write-Host "Error: Unable to uninstall Microsoft Edge via Winget" -ForegroundColor Red Write-Host "Unable to uninstall Microsoft Edge via Winget" -ForegroundColor Red
Write-Output "" Write-Output ""
if ($( Read-Host -Prompt "Would you like to forcefully uninstall Edge? NOT RECOMMENDED! (y/n)" ) -eq 'y') { if ($( Read-Host -Prompt "Would you like to forcefully uninstall Edge? NOT RECOMMENDED! (y/n)" ) -eq 'y') {
@@ -376,9 +370,12 @@ function RemoveApps {
Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like $app } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName } Get-AppxProvisionedPackage -Online | Where-Object { $_.PackageName -like $app } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }
} }
} }
Write-Output ""
} }
# Forcefully removes Microsoft Edge using it's uninstaller
function ForceRemoveEdge { function ForceRemoveEdge {
# Based on work from loadstring1 & ave9858 # Based on work from loadstring1 & ave9858
Write-Output "> Forcefully uninstalling Microsoft Edge..." Write-Output "> Forcefully uninstalling Microsoft Edge..."
@@ -1134,7 +1131,7 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP
} }
} }
else { else {
Write-Host "Selection was cancelled, no apps have been removed!" -ForegroundColor Red Write-Host "Selection was cancelled, no apps have been removed" -ForegroundColor Red
Write-Output "" Write-Output ""
} }
} }
@@ -1147,39 +1144,30 @@ if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPP
# Get & print default settings info from file # Get & print default settings info from file
Foreach ($line in (Get-Content -Path "$PSScriptRoot/SavedSettings" )) { Foreach ($line in (Get-Content -Path "$PSScriptRoot/SavedSettings" )) {
# Remove any spaces before and after the Appname # Remove any spaces before and after the line
$line = $line.Trim() $line = $line.Trim()
# Check if line has # char, show description, add parameter # Check if the line contains a comment
if (-not ($line.IndexOf('#') -eq -1)) { if (-not ($line.IndexOf('#') -eq -1)) {
Write-Output $line.Substring(($line.IndexOf('#') + 1), ($line.Length - $line.IndexOf('#') - 1)) $parameterName = $line.Substring(0, $line.IndexOf('#'))
$paramName = $line.Substring(0, $line.IndexOf('#'))
if ($paramName -eq "RemoveAppsCustom") { # Print parameter description and add parameter to Params list
# If paramName is RemoveAppsCustom, check if CustomAppsFile exists if ($parameterName -eq "RemoveAppsCustom") {
if (Test-Path "$PSScriptRoot/CustomAppsList") { if (-not (Test-Path "$PSScriptRoot/CustomAppsList")) {
# Apps file exists, print list of apps # Apps file does not exist, skip
$appsList = @()
# Get apps list from file
Foreach ($app in (Get-Content -Path "$PSScriptRoot/CustomAppsList" )) {
# Remove any spaces before and after the app name
$app = $app.Trim()
$appsList += $app
}
Write-Host $appsList -ForegroundColor DarkGray
}
else {
# Apps file does not exist, print error and continue to next item
Write-Host "Error: Could not load custom apps list from file, no apps will be removed!" -ForegroundColor Red
continue continue
} }
$appsList = ReadAppslistFromFile "$PSScriptRoot/CustomAppsList"
Write-Output "- Remove $($appsList.Count) apps:"
Write-Host $appsList -ForegroundColor DarkGray
}
else {
Write-Output $line.Substring(($line.IndexOf('#') + 1), ($line.Length - $line.IndexOf('#') - 1))
} }
if (-not $global:Params.ContainsKey($ParameterName)){ if (-not $global:Params.ContainsKey($parameterName)){
$global:Params.Add($paramName, $true) $global:Params.Add($parameterName, $true)
} }
} }
} }
@@ -1203,36 +1191,28 @@ else {
# or added by the user, and the script can exit without making any changes. # or added by the user, and the script can exit without making any changes.
if ($SPParamCount -eq $global:Params.Keys.Count) { if ($SPParamCount -eq $global:Params.Keys.Count) {
Write-Output "The script completed without making any changes." Write-Output "The script completed without making any changes."
AwaitKeyToExit AwaitKeyToExit
} }
else { else {
# Execute all selected/provided parameters # Execute all selected/provided parameters
switch ($global:Params.Keys) { switch ($global:Params.Keys) {
'RemoveApps' { 'RemoveApps' {
RemoveAppsFromFile "$PSScriptRoot/Appslist.txt" Write-Output "> Removing default selection of apps..."
$appsList = ReadAppslistFromFile "$PSScriptRoot/Appslist.txt"
RemoveApps $appsList
continue continue
} }
'RemoveAppsCustom' { 'RemoveAppsCustom' {
if (Test-Path "$PSScriptRoot/CustomAppsList") { if (-not (Test-Path "$PSScriptRoot/CustomAppsList")) {
$appsList = @() Write-Host "> Error: Could not load custom apps list from file, no apps were removed" -ForegroundColor Red
continue
# Get apps list from file
Foreach ($app in (Get-Content -Path "$PSScriptRoot/CustomAppsList" )) {
# Remove any spaces before and after the app name
$app = $app.Trim()
$appsList += $app
}
Write-Output "> Removing $($appsList.Count) apps..."
RemoveApps $appsList
} }
else {
Write-Host "> Could not load custom apps list from file, no apps were removed!" -ForegroundColor Red $appsList = ReadAppslistFromFile "$PSScriptRoot/CustomAppsList"
} Write-Output "> Removing $($appsList.Count) apps..."
RemoveApps $appsList
Write-Output ""
continue continue
} }
'RemoveCommApps' { 'RemoveCommApps' {
@@ -1240,8 +1220,6 @@ else {
$appsList = 'Microsoft.windowscommunicationsapps', 'Microsoft.People' $appsList = 'Microsoft.windowscommunicationsapps', 'Microsoft.People'
RemoveApps $appsList RemoveApps $appsList
Write-Output ""
continue continue
} }
'RemoveW11Outlook' { 'RemoveW11Outlook' {
@@ -1249,8 +1227,6 @@ else {
$appsList = 'Microsoft.OutlookForWindows' $appsList = 'Microsoft.OutlookForWindows'
RemoveApps $appsList RemoveApps $appsList
Write-Output ""
continue continue
} }
'RemoveDevApps' { 'RemoveDevApps' {
@@ -1258,9 +1234,6 @@ else {
$appsList = 'Microsoft.PowerAutomateDesktop', 'Microsoft.RemoteDesktop', 'Windows.DevHome' $appsList = 'Microsoft.PowerAutomateDesktop', 'Microsoft.RemoteDesktop', 'Windows.DevHome'
RemoveApps $appsList RemoveApps $appsList
Write-Output ""
continue continue
} }
'RemoveGamingApps' { 'RemoveGamingApps' {
@@ -1268,9 +1241,6 @@ else {
$appsList = 'Microsoft.GamingApp', 'Microsoft.XboxGameOverlay', 'Microsoft.XboxGamingOverlay' $appsList = 'Microsoft.GamingApp', 'Microsoft.XboxGameOverlay', 'Microsoft.XboxGamingOverlay'
RemoveApps $appsList RemoveApps $appsList
Write-Output ""
continue continue
} }
"ForceRemoveEdge" { "ForceRemoveEdge" {
@@ -1299,9 +1269,6 @@ else {
# Also remove the app package for bing search # Also remove the app package for bing search
$appsList = 'Microsoft.BingSearch' $appsList = 'Microsoft.BingSearch'
RemoveApps $appsList RemoveApps $appsList
Write-Output ""
continue continue
} }
{$_ -in "DisableLockscrTips", "DisableLockscreenTips"} { {$_ -in "DisableLockscrTips", "DisableLockscreenTips"} {