-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWin_CleanPreinstall.ps1
121 lines (110 loc) · 3.9 KB
/
Win_CleanPreinstall.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
# query
# Get-AppxPackage -AllUsers | Select-Object -ExpandProperty Name
$uninstalls = @(
"549981C3F5F10", # Cortana
"BingNews",
"BingWeather",
"Clipchamp.Clipchamp",
"CloudExperienceHost",
"Copilot",
"DevHome",
"GetHelp",
"MicrosoftOffice",
"MicrosoftSolitaireCollection",
"MicrosoftTeams",
"Microsoft.People",
"Microsoft.Todos",
"OneDrive",
"Outlook",
"PowerAutomateDesktop",
"QuickAssist",
"ScreenSketch",
"StickyNotes",
"WindowsCamera",
"windowscommunicationsapps",
"WindowsFeedbackHub",
"WindowsMaps",
"YourPhone",
"ZuneMusic",
"ZuneVideo"
)
function log($msg = "") {
Write-Output $msg;
}
function infoPopup($message, $timeout=1, $icon=64){
$wshell = New-Object -ComObject Wscript.Shell -ErrorAction Inquire
return $wshell.Popup($message, $timeout, "Info", $icon + 0)
}
function RemoveSoftware($name, $displayName=$name) {
$wshell = New-Object -ComObject Wscript.Shell -ErrorAction Inquire
$t = Get-AppxPackage -AllUsers *$name*
$nonRemovable = $t | Where-Object{$_.NonRemovable -eq $True}
$t = $t | Where-Object{$_.NonRemovable -eq $False}
$r = 0
$n = $t.length
if ($nonRemovable.length -gt 0) {
$nr_name = ($nonRemovable.Name -join ', ')
log "[NoRM] - Packages $nr_name cannot be removed."
if ($n -eq 0 ) {
return ($nonRemovable.length * -1)
}
}
if ($n -eq 1) {
$pkg = $t.name
log "[one ] - Package $pkg installed."
$r = $wshell.Popup("Uninstall $displayName : $pkg ?", 0, "Remove 1 Package", 32 + 4)
}
elseif ($n -gt 1) {
log "[many] - $n package for *$name*."
$list = ($t.name -join ", ")
$r = $wshell.Popup("Uninstall $displayName ($n): $list ?", 0, "Remove $n Package", 32 + 4)
}
else {
log "[none] - Package $name not installed."
return
}
if (($r -eq 6)) {
$t | Remove-AppxPackage -AllUsers
if ($? -eq $False) {
log "[ERR ] Package $displayName not removed."
$wshell.Popup("Impossible to remove $displayName.", 1, "Remove Software", 48)
return 0
}
log "[DEL ] Package $displayName removed."
infoPopup("$displayName Uninstalled.")
return $n
}
log "[skip] Skipping $displayName..."
return
}
function MainEntry {
foreach ($appx in $uninstalls) {
RemoveSoftware $appx
}
# Clean TaskBar - Teams Chat
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarMn" -Type "DWord" -Value 0
# Clean TaskBar - Task View
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ShowTaskViewButton" -Type "DWord" -Value 0
# Clean TaskBar - Copilot
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ShowCopilotButton" -Type "DWord" -Value 0
# Clean TaskBar - Widget
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarDa" -Type "DWord" -Value "0"
# Clean TaskBar - Search Box
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "SearchboxTaskbarMode" -Type "DWord" -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search" -Name "SearchboxTaskbarModeCache" -Type "DWord" -Value 1
winget install --id Microsoft.Powershell --source winget
winget install Microsoft.PowerToys
}
try {
MainEntry
}
catch {
Write-Host "Exception:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
Write-Host $_.Exception.StackTrace -ForegroundColor Red
exit 1
}
# Delete Self
$myPsPath = $MyInvocation.MyCommand.Path
Start-Process powershell -ArgumentList "Remove-Item `"$myPsPath`" -Force"