This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
forked from Raphire/Win11Debloat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win11Debloat.ps1
1358 lines (1114 loc) · 55.6 KB
/
Win11Debloat.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#Requires -RunAsAdministrator
[CmdletBinding(SupportsShouldProcess)]
param (
[switch]$Silent,
[switch]$Sysprep,
[switch]$RunAppConfigurator,
[switch]$RunDefaults, [switch]$RunWin11Defaults,
[switch]$RemoveApps,
[switch]$RemoveAppsCustom,
[switch]$RemoveGamingApps,
[switch]$RemoveCommApps,
[switch]$RemoveDevApps,
[switch]$RemoveW11Outlook,
[switch]$ForceRemoveEdge,
[switch]$DisableDVR,
[switch]$DisableTelemetry,
[switch]$DisableBingSearches, [switch]$DisableBing,
[switch]$DisableLockscrTips, [switch]$DisableLockscreenTips,
[switch]$DisableWindowsSuggestions, [switch]$DisableSuggestions,
[switch]$ShowHiddenFolders,
[switch]$ShowKnownFileExt,
[switch]$HideDupliDrive,
[switch]$TaskbarAlignLeft,
[switch]$HideSearchTb, [switch]$ShowSearchIconTb, [switch]$ShowSearchLabelTb, [switch]$ShowSearchBoxTb,
[switch]$HideTaskview,
[switch]$DisableCopilot,
[switch]$DisableRecall,
[switch]$DisableWidgets,
[switch]$HideWidgets,
[switch]$DisableChat,
[switch]$HideChat,
[switch]$ClearStart,
[switch]$ClearStartAllUsers,
[switch]$RevertContextMenu,
[switch]$HideGallery,
[switch]$DisableOnedrive, [switch]$HideOnedrive,
[switch]$Disable3dObjects, [switch]$Hide3dObjects,
[switch]$DisableMusic, [switch]$HideMusic,
[switch]$DisableIncludeInLibrary, [switch]$HideIncludeInLibrary,
[switch]$DisableGiveAccessTo, [switch]$HideGiveAccessTo,
[switch]$DisableShare, [switch]$HideShare
)
# Show error if current powershell environment does not have LanguageMode set to FullLanguage
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
Write-Host "Error: Win11Debloat is unable to run on your system, powershell execution is restricted by security policies" -ForegroundColor Red
Write-Output ""
Write-Output "Press enter to exit..."
Read-Host | Out-Null
Exit
}
# Shows application selection form that allows the user to select what apps they want to remove or keep
function ShowAppSelectionForm {
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
# Initialise form objects
$form = New-Object System.Windows.Forms.Form
$label = New-Object System.Windows.Forms.Label
$button1 = New-Object System.Windows.Forms.Button
$button2 = New-Object System.Windows.Forms.Button
$selectionBox = New-Object System.Windows.Forms.CheckedListBox
$loadingLabel = New-Object System.Windows.Forms.Label
$onlyInstalledCheckBox = New-Object System.Windows.Forms.CheckBox
$checkUncheckCheckBox = New-Object System.Windows.Forms.CheckBox
$initialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$global:selectionBoxIndex = -1
# saveButton eventHandler
$handler_saveButton_Click=
{
$global:SelectedApps = $selectionBox.CheckedItems
# Create file that stores selected apps if it doesn't exist
if (!(Test-Path "$PSScriptRoot/CustomAppsList.txt")) {
$null = New-Item "$PSScriptRoot/CustomAppsList.txt"
}
Set-Content -Path "$PSScriptRoot/CustomAppsList.txt" -Value $global:SelectedApps
$form.Close()
}
# cancelButton eventHandler
$handler_cancelButton_Click=
{
$form.Close()
}
$selectionBox_SelectedIndexChanged=
{
$global:selectionBoxIndex = $selectionBox.SelectedIndex
}
$selectionBox_MouseDown=
{
if ($_.Button -eq [System.Windows.Forms.MouseButtons]::Left) {
if([System.Windows.Forms.Control]::ModifierKeys -eq [System.Windows.Forms.Keys]::Shift) {
if($global:selectionBoxIndex -ne -1) {
$topIndex = $global:selectionBoxIndex
if ($selectionBox.SelectedIndex -gt $topIndex) {
for(($i = ($topIndex)); $i -le $selectionBox.SelectedIndex; $i++){
$selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex))
}
}
elseif ($topIndex -gt $selectionBox.SelectedIndex) {
for(($i = ($selectionBox.SelectedIndex)); $i -le $topIndex; $i++){
$selectionBox.SetItemChecked($i, $selectionBox.GetItemChecked($topIndex))
}
}
}
}
elseif($global:selectionBoxIndex -ne $selectionBox.SelectedIndex) {
$selectionBox.SetItemChecked($selectionBox.SelectedIndex, -not $selectionBox.GetItemChecked($selectionBox.SelectedIndex))
}
}
}
$check_All=
{
for(($i = 0); $i -lt $selectionBox.Items.Count; $i++){
$selectionBox.SetItemChecked($i, $checkUncheckCheckBox.Checked)
}
}
$load_Apps=
{
# Correct the initial state of the form to prevent the .Net maximized form issue
$form.WindowState = $initialFormWindowState
# Reset state to default before loading appslist again
$global:selectionBoxIndex = -1
$checkUncheckCheckBox.Checked = $False
# Show loading indicator
$loadingLabel.Visible = $true
$form.Refresh()
# Clear selectionBox before adding any new items
$selectionBox.Items.Clear()
# Set filePath where Appslist can be found
$appsFile = "$PSScriptRoot/Appslist.txt"
$listOfApps = ""
if ($onlyInstalledCheckBox.Checked -and ($global:wingetInstalled -eq $true)) {
# Attempt to get a list of installed apps via winget, times out after 10 seconds
$job = Start-Job { return winget list --accept-source-agreements --disable-interactivity }
$jobDone = $job | Wait-Job -TimeOut 10
if (-not $jobDone) {
# Show error that the script was unable to get list of apps from winget
[System.Windows.MessageBox]::Show('Unable to load list of installed apps via winget, some apps may not be displayed in the list.','Error','Ok','Error')
}
else {
# Add output of job (list of apps) to $listOfApps
$listOfApps = Receive-Job -Job $job
}
}
# Go through appslist and add items one by one to the selectionBox
Foreach ($app in (Get-Content -Path $appsFile | Where-Object { $_ -notmatch '^\s*$' } )) {
$appChecked = $true
# Remove first # if it exists and set AppChecked to false
if ($app.StartsWith('#')) {
$app = $app.TrimStart("#")
$appChecked = $false
}
# Remove any comments from the Appname
if (-not ($app.IndexOf('#') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf('#'))
}
# Remove any remaining spaces from the Appname
if (-not ($app.IndexOf(' ') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf(' '))
}
$appString = $app.Trim('*')
# Make sure appString is not empty
if ($appString.length -gt 0) {
if ($onlyInstalledCheckBox.Checked) {
# onlyInstalledCheckBox is checked, check if app is installed before adding it to selectionBox
if (-not ($listOfApps -like ("*$appString*")) -and -not (Get-AppxPackage -Name $app)) {
# App is not installed, continue with next item
continue
}
if (($appString -eq "Microsoft.Edge") -and -not ($listOfApps -like "* Microsoft.Edge *")) {
# App is not installed, continue with next item
continue
}
}
# Add the app to the selectionBox and set it's checked status
$selectionBox.Items.Add($appString, $appChecked) | Out-Null
}
}
# Hide loading indicator
$loadingLabel.Visible = $False
# Sort selectionBox alphabetically
$selectionBox.Sorted = $True
}
$form.Text = "Win11Debloat Application Selection"
$form.Name = "appSelectionForm"
$form.DataBindings.DefaultDataSourceUpdateMode = 0
$form.ClientSize = New-Object System.Drawing.Size(400,502)
$form.FormBorderStyle = 'FixedDialog'
$form.MaximizeBox = $False
$button1.TabIndex = 4
$button1.Name = "saveButton"
$button1.DialogResult = [System.Windows.Forms.DialogResult]::OK
$button1.UseVisualStyleBackColor = $True
$button1.Text = "Confirm"
$button1.Location = New-Object System.Drawing.Point(27,472)
$button1.Size = New-Object System.Drawing.Size(75,23)
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($handler_saveButton_Click)
$form.Controls.Add($button1)
$button2.TabIndex = 5
$button2.Name = "cancelButton"
$button2.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$button2.UseVisualStyleBackColor = $True
$button2.Text = "Cancel"
$button2.Location = New-Object System.Drawing.Point(129,472)
$button2.Size = New-Object System.Drawing.Size(75,23)
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$button2.add_Click($handler_cancelButton_Click)
$form.Controls.Add($button2)
$label.Location = New-Object System.Drawing.Point(13,5)
$label.Size = New-Object System.Drawing.Size(400,14)
$Label.Font = 'Microsoft Sans Serif,8'
$label.Text = 'Check apps that you wish to remove, uncheck apps that you wish to keep'
$form.Controls.Add($label)
$loadingLabel.Location = New-Object System.Drawing.Point(16,46)
$loadingLabel.Size = New-Object System.Drawing.Size(300,418)
$loadingLabel.Text = 'Loading apps...'
$loadingLabel.BackColor = "White"
$loadingLabel.Visible = $false
$form.Controls.Add($loadingLabel)
$onlyInstalledCheckBox.TabIndex = 6
$onlyInstalledCheckBox.Location = New-Object System.Drawing.Point(230,474)
$onlyInstalledCheckBox.Size = New-Object System.Drawing.Size(150,20)
$onlyInstalledCheckBox.Text = 'Only show installed apps'
$onlyInstalledCheckBox.add_CheckedChanged($load_Apps)
$form.Controls.Add($onlyInstalledCheckBox)
$checkUncheckCheckBox.TabIndex = 7
$checkUncheckCheckBox.Location = New-Object System.Drawing.Point(16,22)
$checkUncheckCheckBox.Size = New-Object System.Drawing.Size(150,20)
$checkUncheckCheckBox.Text = 'Check/Uncheck all'
$checkUncheckCheckBox.add_CheckedChanged($check_All)
$form.Controls.Add($checkUncheckCheckBox)
$selectionBox.FormattingEnabled = $True
$selectionBox.DataBindings.DefaultDataSourceUpdateMode = 0
$selectionBox.Name = "selectionBox"
$selectionBox.Location = New-Object System.Drawing.Point(13,43)
$selectionBox.Size = New-Object System.Drawing.Size(374,424)
$selectionBox.TabIndex = 3
$selectionBox.add_SelectedIndexChanged($selectionBox_SelectedIndexChanged)
$selectionBox.add_Click($selectionBox_MouseDown)
$form.Controls.Add($selectionBox)
# Save the initial state of the form
$initialFormWindowState = $form.WindowState
# Load apps into selectionBox
$form.add_Load($load_Apps)
# Focus selectionBox when form opens
$form.Add_Shown({$form.Activate(); $selectionBox.Focus()})
# Show the Form
return $form.ShowDialog()
}
# Returns list of apps from the specified file, it trims the app names and removes any comments
function ReadAppslistFromFile {
param (
$appsFilePath
)
$appsList = @()
# 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*$' } )) {
# Remove any comments from the Appname
if (-not ($app.IndexOf('#') -eq -1)) {
$app = $app.Substring(0, $app.IndexOf('#'))
}
# Remove any spaces before and after the Appname
$app = $app.Trim()
$appString = $app.Trim('*')
$appsList += $appString
}
return $appsList
}
# Removes apps specified during function call from all user accounts and from the OS image.
function RemoveApps {
param (
$appslist
)
Foreach ($app in $appsList) {
Write-Output "Attempting to remove $app..."
if (($app -eq "Microsoft.OneDrive") -or ($app -eq "Microsoft.Edge")) {
# Use winget to remove OneDrive and Edge
if ($global:wingetInstalled -eq $false) {
Write-Host "Error: WinGet is either not installed or is outdated, $app could not be removed" -ForegroundColor Red
}
else {
# Uninstall app via winget
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")) {
Write-Host "Unable to uninstall Microsoft Edge via Winget" -ForegroundColor Red
Write-Output ""
if ($( Read-Host -Prompt "Would you like to forcefully uninstall Edge? NOT RECOMMENDED! (y/n)" ) -eq 'y') {
Write-Output ""
ForceRemoveEdge
}
}
}
}
else {
# Use Remove-AppxPackage to remove all other apps
$app = '*' + $app + '*'
# Remove installed app for all existing users
if ($WinVersion -ge 22000){
# Windows 11 build 22000 or later
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers
}
else {
# Windows 10
Get-AppxPackage -Name $app -PackageTypeFilter Main, Bundle, Resource -AllUsers | Remove-AppxPackage -AllUsers
}
# Remove provisioned app from OS image, so the app won't be installed for any new users
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 {
# Based on work from loadstring1 & ave9858
Write-Output "> Forcefully uninstalling Microsoft Edge..."
$regView = [Microsoft.Win32.RegistryView]::Registry32
$hklm = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $regView)
$hklm.CreateSubKey('SOFTWARE\Microsoft\EdgeUpdateDev').SetValue('AllowUninstall', '')
# Create stub (Creating this somehow allows uninstalling edge)
$edgeStub = "$env:SystemRoot\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe"
New-Item $edgeStub -ItemType Directory | Out-Null
New-Item "$edgeStub\MicrosoftEdge.exe" | Out-Null
# Remove edge
$uninstallRegKey = $hklm.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge')
if($uninstallRegKey -ne $null) {
Write-Output "Running uninstaller..."
$uninstallString = $uninstallRegKey.GetValue('UninstallString') + ' --force-uninstall'
Start-Process cmd.exe "/c $uninstallString" -WindowStyle Hidden -Wait
Write-Output "Removing leftover files..."
$appdata = $([Environment]::GetFolderPath('ApplicationData'))
$edgePaths = @(
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk",
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
"$env:APPDATA\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Microsoft Edge.lnk",
"$env:PUBLIC\Desktop\Microsoft Edge.lnk",
"$env:USERPROFILE\Desktop\Microsoft Edge.lnk",
"$appdata\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Tombstones\Microsoft Edge.lnk",
"$appdata\Microsoft\Internet Explorer\Quick Launch\Microsoft Edge.lnk",
"$edgeStub"
)
foreach ($path in $edgePaths){
if (Test-Path -Path $path) {
Remove-Item -Path $path -Force -Recurse -ErrorAction SilentlyContinue
Write-Host " Removed $path" -ForegroundColor DarkGray
}
}
Write-Output "Cleaning up registry..."
# Remove ms edge from autostart
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /v "Microsoft Edge Update" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "MicrosoftEdgeAutoLaunch_A9F6DCE4ABADF4F51CF45CD7129E3C6C" /f *>$null
reg delete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" /v "Microsoft Edge Update" /f *>$null
Write-Output "Microsoft Edge was uninstalled"
}
else {
Write-Output ""
Write-Host "Error: Unable to forcefully uninstall Microsoft Edge, uninstaller could not be found" -ForegroundColor Red
}
Write-Output ""
}
# Execute provided command and strips progress spinners/bars from console output
function Strip-Progress {
param(
[ScriptBlock]$ScriptBlock
)
# Regex pattern to match spinner characters and progress bar patterns
$progressPattern = 'Γû[Æê]|^\s+[-\\|/]\s+$'
# Corrected regex pattern for size formatting, ensuring proper capture groups are utilized
$sizePattern = '(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB) /\s+(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB)'
& $ScriptBlock 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
"ERROR: $($_.Exception.Message)"
} else {
$line = $_ -replace $progressPattern, '' -replace $sizePattern, ''
if (-not ([string]::IsNullOrWhiteSpace($line)) -and -not ($line.StartsWith(' '))) {
$line
}
}
}
}
# Import & execute regfile
function RegImport {
param (
$message,
$path
)
Write-Output $message
if (!$global:Params.ContainsKey("Sysprep")) {
reg import "$PSScriptRoot\Regfiles\$path"
}
else {
reg load "HKU\Default" "C:\Users\Default\NTUSER.DAT" | Out-Null
reg import "$PSScriptRoot\Regfiles\Sysprep\$path"
reg unload "HKU\Default" | Out-Null
}
Write-Output ""
}
# Restart the Windows Explorer process
function RestartExplorer {
Write-Output "> Restarting Windows Explorer process to apply all changes... (This may cause some flickering)"
# Only restart if the powershell process matches the OS architecture
# Restarting explorer from a 32bit Powershell window will fail on a 64bit OS
if ([Environment]::Is64BitProcess -eq [Environment]::Is64BitOperatingSystem)
{
Stop-Process -processName: Explorer -Force
}
else {
Write-Warning "Unable to restart Windows Explorer process, please manually restart your PC to apply all changes."
}
}
# Replace the startmenu for all users, when using the default startmenuTemplate this clears all pinned apps
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
function ReplaceStartMenuForAllUsers {
param (
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
)
Write-Output "> Removing all pinned apps from the start menu for all users..."
# Check if template bin file exists, return early if it doesn't
if (-not (Test-Path $startMenuTemplate)) {
Write-Host "Error: Unable to clear start menu, start2.bin file missing from script folder" -ForegroundColor Red
return
}
# Get path to start menu file for all users
$usersStartMenuPaths = get-childitem -path "C:\Users\*\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState"
# Go through all users and replace the start menu file
ForEach ($startMenuPath in $usersStartMenuPaths) {
ReplaceStartMenu "$($startMenuPath.Fullname)\start2.bin" $startMenuTemplate
}
# Also replace the start menu file for the default user profile
$defaultProfile = "C:\Users\default\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState"
# Create folder if it doesn't exist
if (-not(Test-Path $defaultProfile)) {
new-item $defaultProfile -ItemType Directory -Force | Out-Null
Write-Output "Created LocalState folder for default user"
}
# Copy template to default profile
Copy-Item -Path $startMenuTemplate -Destination $defaultProfile -Force
Write-Output "Replaced start menu for the default user profile"
Write-Output ""
}
# Replace the startmenu for all users, when using the default startmenuTemplate this clears all pinned apps
# Credit: https://lazyadmin.nl/win-11/customize-windows-11-start-menu-layout/
function ReplaceStartMenu {
param (
$startMenuBinFile = "C:\Users\$([Environment]::UserName)\AppData\Local\Packages\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\LocalState\start2.bin",
$startMenuTemplate = "$PSScriptRoot/Start/start2.bin"
)
$userName = $startMenuBinFile.Split("\")[2]
# Check if template bin file exists, return early if it doesn't
if (-not (Test-Path $startMenuTemplate)) {
Write-Host "Error: Unable to clear start menu, start2.bin file missing from script folder" -ForegroundColor Red
return
}
# Check if bin file exists, return early if it doesn't
if (-not (Test-Path $startMenuBinFile)) {
Write-Host "Error: Unable to clear start menu for user $userName, start2.bin file could not found" -ForegroundColor Red
return
}
$backupBinFile = $startMenuBinFile + ".bak"
# Backup current start menu file
Move-Item -Path $startMenuBinFile -Destination $backupBinFile -Force
# Copy template file
Copy-Item -Path $startMenuTemplate -Destination $startMenuBinFile -Force
Write-Output "Replaced start menu for user $userName"
}
# Add parameter to script and write to file
function AddParameter {
param (
$parameterName,
$message
)
# Add key if it doesn't already exist
if (-not $global:Params.ContainsKey($parameterName)) {
$global:Params.Add($parameterName, $true)
}
# Create or clear file that stores last used settings
if (!(Test-Path "$PSScriptRoot/SavedSettings")) {
$null = New-Item "$PSScriptRoot/SavedSettings"
}
elseif ($global:FirstSelection) {
$null = Clear-Content "$PSScriptRoot/SavedSettings"
}
$global:FirstSelection = $false
# Create entry and add it to the file
$entry = "$parameterName#- $message"
Add-Content -Path "$PSScriptRoot/SavedSettings" -Value $entry
}
function PrintHeader {
param (
$title
)
$fullTitle = " Win11Debloat Script - $title"
if($global:Params.ContainsKey("Sysprep")) {
$fullTitle = "$fullTitle (Sysprep mode)"
}
else {
$fullTitle = "$fullTitle (User: $Env:UserName)"
}
Clear-Host
Write-Output "-------------------------------------------------------------------------------------------"
Write-Output $fullTitle
Write-Output "-------------------------------------------------------------------------------------------"
}
function PrintFromFile {
param (
$path
)
Clear-Host
# Get & print script menu from file
Foreach ($line in (Get-Content -Path $path )) {
Write-Output $line
}
}
function AwaitKeyToExit {
# Suppress prompt if Silent parameter was passed
if (-not $Silent) {
Write-Output ""
Write-Output "Press any key to exit..."
$null = [System.Console]::ReadKey()
}
}
##################################################################################################################
# #
# SCRIPT START #
# #
##################################################################################################################
# Check if winget is installed & if it is, check if the version is at least v1.4
if ((Get-AppxPackage -Name "*Microsoft.DesktopAppInstaller*") -and ((winget -v) -replace 'v','' -gt 1.4)) {
$global:wingetInstalled = $true
}
else {
$global:wingetInstalled = $false
# Show warning that requires user confirmation, Suppress confirmation if Silent parameter was passed
if (-not $Silent) {
Write-Warning "Winget is not installed or outdated. This may prevent Win11Debloat from removing certain apps."
Write-Output ""
Write-Output "Press any key to continue anyway..."
$null = [System.Console]::ReadKey()
}
}
# Get current Windows build version to compare against features
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
# Hide progress bars for app removal, as they block Win11Debloat's output
$ProgressPreference = 'SilentlyContinue'
$global:Params = $PSBoundParameters
$global:FirstSelection = $true
$SPParams = 'WhatIf', 'Confirm', 'Verbose', 'Silent', 'Sysprep'
$SPParamCount = 0
# Count how many SPParams exist within Params
# This is later used to check if any options were selected
foreach ($Param in $SPParams) {
if ($global:Params.ContainsKey($Param)) {
$SPParamCount++
}
}
if ($global:Params.ContainsKey("Sysprep")) {
# Exit script if default user directory or NTUSER.DAT file cannot be found
if (-not (Test-Path "C:\Users\Default\NTUSER.DAT")) {
Write-Host "Error: Unable to start Win11Debloat in Sysprep mode, cannot find default user folder at 'C:\Users\Default\'" -ForegroundColor Red
AwaitKeyToExit
Exit
}
# Exit script if run in Sysprep mode on Windows 10
if ($WinVersion -lt 22000) {
Write-Host "Error: Win11Debloat Sysprep mode is not supported on Windows 10" -ForegroundColor Red
AwaitKeyToExit
Exit
}
}
# Remove SavedSettings file if it exists and is empty
if ((Test-Path "$PSScriptRoot/SavedSettings") -and ([String]::IsNullOrWhiteSpace((Get-content "$PSScriptRoot/SavedSettings")))) {
Remove-Item -Path "$PSScriptRoot/SavedSettings" -recurse
}
# Only run the app selection form if the 'RunAppConfigurator' parameter was passed to the script
if ($RunAppConfigurator) {
PrintHeader "App Configurator"
$result = ShowAppSelectionForm
# Show different message based on whether the app selection was saved or cancelled
if ($result -ne [System.Windows.Forms.DialogResult]::OK) {
Write-Host "App configurator was closed without saving." -ForegroundColor Red
}
else {
Write-Output "Your app selection was saved to the 'CustomAppsList' file in the root folder of the script."
}
AwaitKeyToExit
Exit
}
# Change script execution based on provided parameters or user input
if ((-not $global:Params.Count) -or $RunDefaults -or $RunWin11Defaults -or ($SPParamCount -eq $global:Params.Count)) {
if ($RunDefaults -or $RunWin11Defaults) {
$Mode = '1'
}
else {
# Show menu and wait for user input, loops until valid input is provided
Do {
$ModeSelectionMessage = "Please select an option (1/2/3/0)"
PrintHeader 'Menu'
Write-Output "(1) Default Mode: Apply the default settings"
Write-Output "(2) Custom Mode: Modify the script to your needs"
Write-Output "(3) App removal mode: Select & remove apps, without making other changes"
# Only show this option if SavedSettings file exists
if (Test-Path "$PSScriptRoot/SavedSettings") {
Write-Output "(4) Apply saved custom settings from last time"
$ModeSelectionMessage = "Please select an option (1/2/3/4/0)"
}
Write-Output ""
Write-Output "(0) Show more information"
Write-Output ""
Write-Output ""
$Mode = Read-Host $ModeSelectionMessage
# Show information based on user input, Suppress user prompt if Silent parameter was passed
if ($Mode -eq '0') {
# Get & print script information from file
PrintFromFile "$PSScriptRoot/Menus/Info"
Write-Output ""
Write-Output "Press any key to go back..."
$null = [System.Console]::ReadKey()
}
elseif (($Mode -eq '4')-and -not (Test-Path "$PSScriptRoot/SavedSettings")) {
$Mode = $null
}
}
while ($Mode -ne '1' -and $Mode -ne '2' -and $Mode -ne '3' -and $Mode -ne '4')
}
# Add execution parameters based on the mode
switch ($Mode) {
# Default mode, loads defaults after confirmation
'1' {
# Print the default settings & require userconfirmation, unless Silent parameter was passed
if (-not $Silent) {
PrintFromFile "$PSScriptRoot/Menus/DefaultSettings"
Write-Output ""
Write-Output "Press enter to execute the script or press CTRL+C to quit..."
Read-Host | Out-Null
}
$DefaultParameterNames = 'RemoveApps','DisableTelemetry','DisableBing','DisableLockscreenTips','DisableSuggestions','ShowKnownFileExt','DisableWidgets','HideChat','DisableCopilot'
PrintHeader 'Default Mode'
# Add default parameters if they don't already exist
foreach ($ParameterName in $DefaultParameterNames) {
if (-not $global:Params.ContainsKey($ParameterName)){
$global:Params.Add($ParameterName, $true)
}
}
# Only add this option for Windows 10 users, if it doesn't already exist
if ((get-ciminstance -query "select caption from win32_operatingsystem where caption like '%Windows 10%'") -and (-not $global:Params.ContainsKey('Hide3dObjects'))) {
$global:Params.Add('Hide3dObjects', $Hide3dObjects)
}
}
# Custom mode, show & add options based on user input
'2' {
# Get current Windows build version to compare against features
$WinVersion = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild
PrintHeader 'Custom Mode'
# Show options for removing apps, only continue on valid input
Do {
Write-Host "Options:" -ForegroundColor Yellow
Write-Host " (n) Don't remove any apps" -ForegroundColor Yellow
Write-Host " (1) Only remove the default selection of bloatware apps from 'Appslist.txt'" -ForegroundColor Yellow
Write-Host " (2) Remove default selection of bloatware apps, aswell as mail & calendar apps, developer apps and gaming apps" -ForegroundColor Yellow
Write-Host " (3) Select which apps to remove and which to keep" -ForegroundColor Yellow
$RemoveAppsInput = Read-Host "Remove any pre-installed apps? (n/1/2/3)"
# Show app selection form if user entered option 3
if ($RemoveAppsInput -eq '3') {
$result = ShowAppSelectionForm
if ($result -ne [System.Windows.Forms.DialogResult]::OK) {
# User cancelled or closed app selection, show error and change RemoveAppsInput so the menu will be shown again
Write-Output ""
Write-Host "Cancelled application selection, please try again" -ForegroundColor Red
$RemoveAppsInput = 'c'
}
Write-Output ""
}
}
while ($RemoveAppsInput -ne 'n' -and $RemoveAppsInput -ne '0' -and $RemoveAppsInput -ne '1' -and $RemoveAppsInput -ne '2' -and $RemoveAppsInput -ne '3')
# Select correct option based on user input
switch ($RemoveAppsInput) {
'1' {
AddParameter 'RemoveApps' 'Remove default selection of bloatware apps'
}
'2' {
AddParameter 'RemoveApps' 'Remove default selection of bloatware apps'
AddParameter 'RemoveCommApps' 'Remove the Mail, Calendar, and People apps'
AddParameter 'RemoveW11Outlook' 'Remove the new Outlook for Windows app'
AddParameter 'RemoveDevApps' 'Remove developer-related apps'
AddParameter 'RemoveGamingApps' 'Remove the Xbox App and Xbox Gamebar'
AddParameter 'DisableDVR' 'Disable Xbox game/screen recording'
}
'3' {
Write-Output "You have selected $($global:SelectedApps.Count) apps for removal"
AddParameter 'RemoveAppsCustom' "Remove $($global:SelectedApps.Count) apps:"
Write-Output ""
if ($( Read-Host -Prompt "Disable Xbox game/screen recording? Also stops gaming overlay popups (y/n)" ) -eq 'y') {
AddParameter 'DisableDVR' 'Disable Xbox game/screen recording'
}
}
}
# Only show this option for Windows 11 users running build 22621 or later
if ($WinVersion -ge 22621){
Write-Output ""
if ($global:Params.ContainsKey("Sysprep")) {
if ($( Read-Host -Prompt "Remove all pinned apps from the start menu for all existing and new users? (y/n)" ) -eq 'y') {
AddParameter 'ClearStartAllUsers' 'Remove all pinned apps from the start menu for existing and new users'
}
}
else {
Do {
Write-Host "Options:" -ForegroundColor Yellow
Write-Host " (n) Don't remove any pinned apps from the start menu" -ForegroundColor Yellow
Write-Host " (1) Remove all pinned apps from the start menu for this user only ($([Environment]::UserName))" -ForegroundColor Yellow
Write-Host " (2) Remove all pinned apps from the start menu for all existing and new users" -ForegroundColor Yellow
$ClearStartInput = Read-Host "Remove all pinned apps from the start menu? (n/1/2)"
}
while ($ClearStartInput -ne 'n' -and $ClearStartInput -ne '0' -and $ClearStartInput -ne '1' -and $ClearStartInput -ne '2')
# Select correct option based on user input
switch ($ClearStartInput) {
'1' {
AddParameter 'ClearStart' "Remove all pinned apps from the start menu for this user only"
}
'2' {
AddParameter 'ClearStartAllUsers' "Remove all pinned apps from the start menu for all existing and new users"
}
}
}
}
Write-Output ""
if ($( Read-Host -Prompt "Disable telemetry, diagnostic data, activity history, app-launch tracking and targeted ads? (y/n)" ) -eq 'y') {
AddParameter 'DisableTelemetry' 'Disable telemetry, diagnostic data, activity history, app-launch tracking & targeted ads'
}
Write-Output ""
if ($( Read-Host -Prompt "Disable tips, tricks, suggestions and ads in start, settings, notifications, explorer and lockscreen? (y/n)" ) -eq 'y') {
AddParameter 'DisableSuggestions' 'Disable tips, tricks, suggestions and ads in start, settings, notifications and File Explorer'
AddParameter 'DisableLockscreenTips' 'Disable tips & tricks on the lockscreen'
}
Write-Output ""
if ($( Read-Host -Prompt "Disable & remove bing web search, bing AI & cortana in Windows search? (y/n)" ) -eq 'y') {
AddParameter 'DisableBing' 'Disable & remove bing web search, bing AI & cortana in Windows search'
}
# Only show this option for Windows 11 users running build 22621 or later
if ($WinVersion -ge 22621){
Write-Output ""
if ($( Read-Host -Prompt "Disable Windows Copilot? This applies to all users (y/n)" ) -eq 'y') {
AddParameter 'DisableCopilot' 'Disable Windows copilot'
}
Write-Output ""
if ($( Read-Host -Prompt "Disable Windows Recall snapshots? This applies to all users (y/n)" ) -eq 'y') {
AddParameter 'DisableRecall' 'Disable Windows Recall snapshots'
}
}
# Only show this option for Windows 11 users running build 22000 or later
if ($WinVersion -ge 22000){
Write-Output ""
if ($( Read-Host -Prompt "Restore the old Windows 10 style context menu? (y/n)" ) -eq 'y') {
AddParameter 'RevertContextMenu' 'Restore the old Windows 10 style context menu'
}
}
Write-Output ""
if ($( Read-Host -Prompt "Do you want to make any changes to the taskbar and related services? (y/n)" ) -eq 'y') {
# Only show these specific options for Windows 11 users running build 22000 or later
if ($WinVersion -ge 22000){
Write-Output ""
if ($( Read-Host -Prompt " Align taskbar buttons to the left side? (y/n)" ) -eq 'y') {
AddParameter 'TaskbarAlignLeft' 'Align taskbar icons to the left'
}
# Show options for search icon on taskbar, only continue on valid input
Do {
Write-Output ""
Write-Host " Options:" -ForegroundColor Yellow
Write-Host " (n) No change" -ForegroundColor Yellow
Write-Host " (1) Hide search icon from the taskbar" -ForegroundColor Yellow
Write-Host " (2) Show search icon on the taskbar" -ForegroundColor Yellow
Write-Host " (3) Show search icon with label on the taskbar" -ForegroundColor Yellow
Write-Host " (4) Show search box on the taskbar" -ForegroundColor Yellow
$TbSearchInput = Read-Host " Hide or change the search icon on the taskbar? (n/1/2/3/4)"
}
while ($TbSearchInput -ne 'n' -and $TbSearchInput -ne '0' -and $TbSearchInput -ne '1' -and $TbSearchInput -ne '2' -and $TbSearchInput -ne '3' -and $TbSearchInput -ne '4')
# Select correct taskbar search option based on user input
switch ($TbSearchInput) {
'1' {
AddParameter 'HideSearchTb' 'Hide search icon from the taskbar'
}
'2' {
AddParameter 'ShowSearchIconTb' 'Show search icon on the taskbar'
}
'3' {
AddParameter 'ShowSearchLabelTb' 'Show search icon with label on the taskbar'
}
'4' {
AddParameter 'ShowSearchBoxTb' 'Show search box on the taskbar'
}
}
Write-Output ""
if ($( Read-Host -Prompt " Hide the taskview button from the taskbar? (y/n)" ) -eq 'y') {
AddParameter 'HideTaskview' 'Hide the taskview button from the taskbar'
}
}
Write-Output ""
if ($( Read-Host -Prompt " Disable the widgets service and hide the icon from the taskbar? (y/n)" ) -eq 'y') {
AddParameter 'DisableWidgets' 'Disable the widget service & hide the widget (news and interests) icon from the taskbar'
}
# Only show this options for Windows users running build 22621 or earlier
if ($WinVersion -le 22621){
Write-Output ""
if ($( Read-Host -Prompt " Hide the chat (meet now) icon from the taskbar? (y/n)" ) -eq 'y') {
AddParameter 'HideChat' 'Hide the chat (meet now) icon from the taskbar'