-
Notifications
You must be signed in to change notification settings - Fork 428
/
UWScript.ps1
2692 lines (2279 loc) · 102 KB
/
UWScript.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
# Check if script is running as Administrator
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
Try {
Start-Process PowerShell.exe -ArgumentList ("-NoProfile -ExecutionPolicy Bypass -File `"{0}`"" -f $PSCommandPath) -Verb RunAs
Exit
}
Catch {
Write-Host "Failed to run as Administrator. Please rerun with elevated privileges."
Exit
}
}
# Set window title and color scheme
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + " (Administrator)"
$Host.UI.RawUI.BackgroundColor = "Black"
$Host.PrivateData.ProgressBackgroundColor = "Black"
$Host.PrivateData.ProgressForegroundColor = "White"
Clear-Host
# Center the PowerShell window
$psWindow = Get-Process -Id $pid | ForEach-Object { $_.MainWindowHandle }
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WindowCentering {
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[StructLayout(LayoutKind.Sequential)]
public struct RECT {
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public static void CenterWindow(IntPtr hWnd) {
RECT rect;
GetWindowRect(hWnd, out rect);
int windowWidth = rect.Right - rect.Left;
int windowHeight = rect.Bottom - rect.Top;
int screenWidth = GetSystemMetrics(0);
int screenHeight = GetSystemMetrics(1);
int x = (screenWidth / 2) - (windowWidth / 2);
int y = (screenHeight / 2) - (windowHeight / 2);
MoveWindow(hWnd, x, y, windowWidth, windowHeight, true);
}
[DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex);
}
"@
[WindowCentering]::CenterWindow($psWindow)
# START OF MENU FUNCTIONS
$script:loop = $true
# Header
function Show-Header {
Clear-Host
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " UWScript " -ForegroundColor Yellow
Write-Host "============================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "NO LIABILITY ACCEPTED, PROCEED WITH CAUTION!" -ForegroundColor Black -BackgroundColor Red
Write-Host ""
}
# Main Menu
function Show-MainMenu {
Show-Header
Write-Host "Main Menu:" -ForegroundColor Yellow
Write-Host "1. Software & Apps"
Write-Host "2. Privacy & Security"
Write-Host "3. Windows Updates"
Write-Host "4. Optimize Registry"
Write-Host "5. Tasks & Services"
Write-Host "6. Power Settings"
Write-Host "0. Exit"
$choice = Read-Host "Select an option (0-6)"
switch ($choice) {
"1" { Show-SoftwareMenu } # Call the Software & Apps menu
"2" { Show-PrivacySecurityMenu } # Call the Privacy & Security menu
"3" { Show-WindowsUpdateMenu } # Call the Windows Updates menu
"4" { Show-OptimizeRegistryMenu } # Call the Optimize Registry menu
"5" { Show-TasksServicesMenu } # Call the Tasks & Services menu
"6" { Show-PowerSettingsMenu } # Call the Power Settings menu
"0" { $script:loop = $false } # Exit
default {
Write-Host "Invalid selection. Please try again." -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
}
# Reusable Menu Function
function Show-Menu {
param (
[string]$menuTitle,
[string[]]$options,
[hashtable]$actions,
[string]$instructions = "Select an option",
[switch]$showHeader
)
# Display the header if specified
if ($showHeader) {
Show-Header
}
# Display the menu title
Write-Host "$menuTitle" -ForegroundColor Yellow
# Display the "Back" option as "0"
Write-Host "0. Main Menu" -ForegroundColor Cyan
# Display the options starting from 1
for ($i = 0; $i -lt $options.Length; $i++) {
Write-Host "$($i + 1). $($options[$i])"
}
Write-Host ""
$choice = Read-Host "$instructions"
if ($choice -eq "0") {
return # Return to the previous menu or exit current menu
}
elseif ($actions.ContainsKey($choice)) {
# Execute the corresponding action
& $actions[$choice]
}
else {
Write-Host "Invalid choice. Try again." -ForegroundColor Red
Start-Sleep -Seconds 1
Show-Menu -menuTitle $menuTitle -options $options -actions $actions -showHeader:$showHeader
}
}
# 1. Software & Apps Menu
function Show-SoftwareMenu {
Show-Menu -menuTitle "Software & Apps" `
-options @("Install Software", "Remove Bloatware Apps") `
-actions @{
"1" = { Show-AppInstallMenu }
"2" = { Show-AppRemovalMenu }
} `
-showHeader
}
# Install Software Menu
function Show-AppInstallMenu {
Show-Menu -menuTitle "Select an app to install" `
-options @("Microsoft Store", "Browser Menu", "UniGetUI (Software Manager)") `
-actions @{
"1" = { Install-Store }
"2" = { Show-BrowserInstallMenu }
"3" = { Install-AppWithWinGet -AppName "MartiCliment.UniGetUI" -FriendlyName "UniGetUI (Software Manager)" }
} `
-showHeader
}
function Show-BrowserInstallMenu {
Show-Menu -menuTitle "Select a Browser to install" `
-options @("Thorium Browser", "Mozilla Firefox", "Microsoft Edge", "Google Chrome", "Brave Browser") `
-actions @{
"1" = { Install-AppWithWinGet -AppName "Alex313031.Thorium" -FriendlyName "Thorium Browser" }
"2" = { Install-AppWithWinGet -AppName "Mozilla.Firefox" -FriendlyName "Mozilla Firefox" }
"3" = { Install-AppWithWinGet -AppName "Microsoft.Edge" -FriendlyName "Microsoft Edge" }
"4" = { Install-AppWithWinGet -AppName "Google.Chrome" -FriendlyName "Google Chrome" }
"5" = { Install-AppWithWinGet -AppName "Brave.Brave" -FriendlyName "Brave Browser" }
} `
-showHeader
}
# Remove Bloatware Apps Menu
function Show-AppRemovalMenu {
Show-Menu -menuTitle "Remove Windows Bloatware Apps" `
-options @("Remove ALL Windows Apps") `
-actions @{
"1" = { Remove-Apps }
} `
-showHeader
}
# 2. Privacy & Security Menu
function Show-PrivacySecurityMenu {
Show-Menu -menuTitle "Privacy & Security" `
-options @("Check Windows Defender Status", "Check User Account Control Status", "Apply Recommended Privacy Settings", "Apply Windows Default Privacy Settings") `
-actions @{
"1" = { Get-WindowsDefenderStatus }
"2" = { Get-UACStatus }
"3" = { Set-RecommendedPrivacySettings }
"4" = { Set-DefaultPrivacySettings }
} `
-showHeader
}
# 3. Windows Updates Menu
function Show-WindowsUpdateMenu {
Show-Menu -menuTitle "Windows Update Settings" `
-options @("Set Recommended Update Settings", "Set Default Update Settings") `
-actions @{
"1" = { Set-RecommendedUpdateSettings }
"2" = { Set-DefaultUpdateSettings }
} `
-showHeader
}
# 4. Optimize Registry Menu
function Show-OptimizeRegistryMenu {
Show-Menu -menuTitle "Optimize Windows Registry" `
-options @("Set Recommended Registry Settings", "Set Default Registry Settings") `
-actions @{
"1" = { Set-RecommendedHKLMRegistry; Set-RecommendedHKCURegistry }
"2" = { Set-DefaultHKLMRegistry; Set-DefaultHKCURegistry }
} `
-showHeader
}
# 5. Tasks & Services Menu
function Show-TasksServicesMenu {
Show-Menu -menuTitle "Windows Services & Scheduled Tasks" `
-options @("Minimal Services", "Default Services", "Disable Scheduled Tasks", "Enable Scheduled Tasks") `
-actions @{
"1" = { Set-ServiceStartup }
"2" = { Set-DefaultServices }
"3" = { Disable-ScheduledTasks }
"4" = { Enable-ScheduledTasks }
} `
-showHeader
}
# 6. Power Settings Menu
function Show-PowerSettingsMenu {
Show-Menu -menuTitle "Power Settings" `
-options @("Recommended Power Settings", "Default Power Settings") `
-actions @{
"1" = { Set-RecommendedPowerSettings }
"2" = { Set-DefaultPowerSettings }
} `
-showHeader
}
# END OF MENU FUNCTIONS
# Define Unattended Windows Installation Variables & Functions
# Check if the marker file exists to determine if we are in the specialize phase
$markerFilePath = "C:\specialize_marker.txt"
$isSpecializePhase = Test-Path $markerFilePath
# Function to Pause scripts only when not in Specialize Phase
function Wait-IfNotSpecialize {
if (-not $isSpecializePhase) {
Pause
}
}
# START OF COMMAND & OPERATION FUNCTIONS
# Start of Software & Apps Functions
# Install Software Functions
# Check for internet connection
function Test-InternetConnection {
Try {
$connection = Test-Connection -ComputerName www.microsoft.com -Count 1 -ErrorAction Stop
if ($connection) {
return $true
}
}
Catch {
return $false
}
}
# Install the Microsoft Store
function Install-Store {
Clear-Host
# Check for internet connection
if (-not (Test-InternetConnection)) {
Write-Host "No internet connection detected. Please connect to the internet and try again." -BackgroundColor Red
Wait-IfNotSpecialize
return
}
# If internet connection is available, continue with installation
Show-Header
Write-Host "Installing Microsoft Store . . ."
Try {
wsreset -i -ErrorAction SilentlyContinue
Show-Header
Write-Host "Microsoft Store is being installed silently in the background." -BackgroundColor Green
Write-Host "Please allow a few minutes for it to install and use it to reinstall the necessary apps manually."
}
Catch {
Show-Header
Write-Host "An error occurred while trying to install the Microsoft Store. Please try again later." -BackgroundColor Red
}
Wait-IfNotSpecialize
}
# Function to check if WinGet is installed, install if necessary, and check for updates
function Test-WinGetStatus {
# Helper function to check if WinGet is installed
function Test-WinGetInstalled {
Try {
winget --version | Out-Null
return $true
}
Catch {
return $false
}
}
# Helper function to install required dependencies from GitHub
function Install-WinGetDependencies {
Show-Header
Write-Host "Installing required dependencies, please wait . . ." -ForegroundColor Yellow
# Define the URLs and paths for dependencies
$dependencyUrls = @(
@{Url = "https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx"; Path = "$env:TEMP\Microsoft.UI.Xaml.2.8.appx" },
@{Url = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"; Path = "$env:TEMP\Microsoft.VCLibs.140.00.UWPDesktop.x64.appx" }
)
# Download and install each dependency
foreach ($dependency in $dependencyUrls) {
Try {
Start-BitsTransfer -Source $dependency.Url -Destination $dependency.Path -TransferType Download -ErrorAction Stop | Out-Null
Show-Header
Try {
Add-AppxPackage -Path $dependency.Path
Show-Header
}
Catch {
Write-Host "Failed to install $($dependency.Path). Please install it manually from the URL: $($dependency.Url)" -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
}
Catch {
Write-Host "Failed to download $($dependency.Path). Check your internet connection and try again." -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
}
}
# Function to install WinGet from GitHub if not found
function Install-WinGet {
Show-Header
Write-Host "WinGet is not installed. Downloading the latest version from GitHub..." -ForegroundColor Yellow
# Ensure internet connection is active
if (-not (Test-InternetConnection)) {
Show-Header
Write-Host "No internet connection detected. Please connect to the internet and try again." -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
# Install the required dependencies
Show-Header
Install-WinGetDependencies
# Define GitHub URL for WinGet releases
$wingetDownloadUrl = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$wingetInstallerPath = "$env:TEMP\WinGetInstaller.msixbundle"
Try {
Show-Header
Write-Host "Starting download of WinGet installer using BITS..."
Start-BitsTransfer -Source $wingetDownloadUrl -Destination $wingetInstallerPath -TransferType Download -ErrorAction Stop | Out-Null
# Confirm the file was downloaded successfully
if (-not (Test-Path $wingetInstallerPath) -or (Get-Item $wingetInstallerPath).Length -eq 0) {
Show-Header
Write-Host "The download failed or the file is empty. Please try downloading manually from: $wingetDownloadUrl" -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
Show-Header
Write-Host "WinGet installer downloaded successfully."
# Install the downloaded WinGet installer
Try {
Add-AppxPackage -Path $wingetInstallerPath
Show-Header
Write-Host "WinGet installed successfully." -ForegroundColor Green
}
Catch {
Show-Header
Write-Host "Failed to install WinGet. Please install it manually from the GitHub page: https://github.com/microsoft/winget-cli/releases" -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
}
Catch {
Show-Header
Write-Host "Failed to download the WinGet installer. Check your internet connection and try again." -ForegroundColor Red
Wait-IfNotSpecialize
Exit
}
}
# Check if WinGet is installed, if not, install it
if (-not (Test-WinGetInstalled)) {
Install-WinGet
}
# Once installed, check for updates
Show-Header
Write-Host "Checking for WinGet updates..."
Try {
$updateCheck = winget upgrade --id Microsoft.WinGet -e --accept-package-agreements --accept-source-agreements 2>&1
if ($updateCheck -match "No installed package found" -or $updateCheck -match "No applicable upgrade found") {
Show-Header
Write-Host "WinGet is already up-to-date." -ForegroundColor Green
}
elseif ($updateCheck -match "An applicable upgrade is available") {
# Perform the upgrade if available
Show-Header
Write-Host "An update is available for WinGet. Upgrading now..."
Try {
winget upgrade --id Microsoft.WinGet -e --accept-package-agreements --accept-source-agreements | Out-Null
if ($LASTEXITCODE -eq 0) {
Show-Header
Write-Host "WinGet updated successfully." -ForegroundColor Green
}
else {
Show-Header
Write-Host "Failed to update WinGet. Proceeding with app installation..." -ForegroundColor Yellow
}
}
Catch {
Show-Header
Write-Host "An error occurred while upgrading WinGet. Proceeding with app installation..." -ForegroundColor Yellow
}
}
else {
Show-Header
Write-Host "Could not determine WinGet update status. Proceeding with app installation..." -ForegroundColor Yellow
}
}
Catch {
Show-Header
Write-Host "An error occurred while checking for WinGet updates. Proceeding with app installation..." -ForegroundColor Yellow
}
}
# Function to install an app using WinGet
function Install-AppWithWinGet {
param (
[string]$AppName,
[string]$FriendlyName
)
Show-Header
# Check for internet connection
if (-not (Test-InternetConnection)) {
Show-Header
Write-Host "No internet connection detected. Please connect to the internet and try again." -BackgroundColor Red
Wait-IfNotSpecialize
return
}
# Update WinGet to ensure it's the latest version
Show-Header
Test-WinGetStatus
# Continue with app installation
Show-Header
Write-Host "Installing $FriendlyName using WinGet . . ."
Try {
# Attempt to install or upgrade the app using WinGet
$installOutput = winget install --id $AppName -e --silent --accept-package-agreements --accept-source-agreements 2>&1
if ($installOutput -match "Found an existing package already installed" -and $installOutput -match "No available upgrade found") {
Write-Host "$FriendlyName is already installed and up-to-date." -BackgroundColor Green
}
elseif ($installOutput -match "Successfully installed") {
Show-Header
Write-Host "$FriendlyName installation completed successfully." -BackgroundColor Green
}
elseif ($installOutput -match "No package found") {
Show-Header
Write-Host "Failed to install $FriendlyName using ID '$AppName'. Package not found or check your internet connection." -BackgroundColor Red
}
else {
Show-Header
Write-Host "An issue occurred during the installation of $FriendlyName. Please check the app ID or try again later." -BackgroundColor Red
}
}
Catch {
Show-Header
Write-Host "An unexpected error occurred while installing $FriendlyName." -BackgroundColor Red
}
Wait-IfNotSpecialize
}
# Remove Bloatware Apps Functions
# Define Packages
$appxPackages = @(
'Microsoft.Microsoft3DViewer', 'Microsoft.BingSearch', 'Microsoft.WindowsCamera', 'Clipchamp.Clipchamp',
'Microsoft.WindowsAlarms', 'Microsoft.549981C3F5F10', 'Microsoft.Windows.DevHome',
'MicrosoftCorporationII.MicrosoftFamily', 'Microsoft.WindowsFeedbackHub', 'Microsoft.GetHelp',
'microsoft.windowscommunicationsapps', 'Microsoft.WindowsMaps', 'Microsoft.ZuneVideo',
'Microsoft.BingNews', 'Microsoft.MicrosoftOfficeHub', 'Microsoft.Office.OneNote',
'Microsoft.OutlookForWindows', 'Microsoft.People', 'Microsoft.Windows.Photos',
'Microsoft.PowerAutomateDesktop', 'MicrosoftCorporationII.QuickAssist', 'Microsoft.SkypeApp',
'Microsoft.MicrosoftSolitaireCollection', 'Microsoft.MicrosoftStickyNotes', 'MSTeams',
'Microsoft.Getstarted', 'Microsoft.Todos', 'Microsoft.WindowsSoundRecorder', 'Microsoft.BingWeather',
'Microsoft.ZuneMusic', 'Microsoft.WindowsTerminal', 'Microsoft.Xbox.TCUI', 'Microsoft.XboxApp',
'Microsoft.XboxGameOverlay', 'Microsoft.XboxGamingOverlay', 'Microsoft.XboxIdentityProvider',
'Microsoft.XboxSpeechToTextOverlay', 'Microsoft.GamingApp', 'Microsoft.YourPhone', 'Microsoft.OneDrive',
'Microsoft.549981C3F5F10', 'Microsoft.MixedReality.Portal', 'Microsoft.ScreenSketch'
'Microsoft.Windows.Ai.Copilot.Provider', 'Microsoft.Copilot', 'Microsoft.Copilot_8wekyb3d8bbwe',
'Microsoft.WindowsMeetNow', 'Microsoft.WindowsStore', 'Microsoft.Paint', 'Microsoft.MSPaint'
)
# Define Windows Capabilities
$capabilities = @(
'Browser.InternetExplorer', 'MathRecognizer', 'OpenSSH.Client',
'Microsoft.Windows.PowerShell.ISE', 'App.Support.QuickAssist', 'App.StepsRecorder',
'Media.WindowsMediaPlayer', 'Microsoft.Windows.WordPad', 'Microsoft.Windows.MSPaint'
)
# Apply registry mods to prevent reinstallation and disable features
function Set-AppsRegistry {
$MultilineComment = @"
Windows Registry Editor Version 5.00
; --Application and Feature Restrictions--
; Disable Windows Copilot system-wide
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot]
"TurnOffWindowsCopilot"=dword:00000001
; Prevents Dev Home Installation
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\DevHomeUpdate]
; Prevents New Outlook for Windows Installation
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\OutlookUpdate]
; Prevents Chat Auto Installation
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications]
"ConfigureChatAutoInstall"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Chat]
"ChatIcon"=dword:00000003
; Disables Cortana
[HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Windows Search]
"AllowCortana"=dword:00000000
; Disables OneDrive Automatic Backups of Important Folders (Documents, Pictures etc.)
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\OneDrive]
"KFMBlockOptIn"=dword:00000001
"@
Set-Content -Path "$env:TEMP\Windows_Apps.reg" -Value $MultilineComment -Force -ErrorAction SilentlyContinue
Regedit.exe /S "$env:TEMP\Windows_Apps.reg" -Force -ErrorAction SilentlyContinue
}
# Removes OneDrive during Windows Installation
function Remove-OneDrive {
Remove-Item "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" -ErrorAction SilentlyContinue
Remove-Item "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.exe" -ErrorAction SilentlyContinue
Remove-Item "C:\Windows\System32\OneDriveSetup.exe" -ErrorAction SilentlyContinue
Remove-Item "C:\Windows\SysWOW64\OneDriveSetup.exe" -ErrorAction SilentlyContinue
}
# Uninstalls OneDrive in existing Windows Installation
function Uninstall-OneDrive {
# stop onedrive running
Stop-Process -Force -Name OneDrive -ErrorAction SilentlyContinue | Out-Null
# uninstall onedrive w10
cmd /c "C:\Windows\SysWOW64\OneDriveSetup.exe -uninstall >nul 2>&1"
# clean onedrive w10
Get-ScheduledTask | Where-Object { $_.Taskname -match 'OneDrive' } | Unregister-ScheduledTask -Confirm:$false
# uninstall onedrive w11
cmd /c "C:\Windows\System32\OneDriveSetup.exe -uninstall >nul 2>&1"
}
# Disables Recall
function Disable-Recall {
Dism /Online /Disable-Feature /Featurename:Recall /NoRestart | Out-Null
}
# Remove All Bloatware (UWP) Apps from Windows.
function Remove-Apps {
Show-Header
Write-Host "Are You Sure You Want to Remove ALL Windows Apps? (Y/N)" -ForegroundColor Black -Backgroundcolor Yellow
Write-Host "Includes: OneDrive, Teams, Outlook for Windows and more . . ." -ForegroundColor Black -Backgroundcolor Yellow
Write-Host "(CAUTION! Can't be Undone!)" -BackgroundColor Red
$confirmation = Read-Host "Enter your choice"
if ($confirmation -eq 'Y' -or $confirmation -eq 'y') {
Show-Header
Write-Host "Removing Pre-installed Apps and Features. Please wait . . ."
# Bloatware Apps
Get-AppxPackage -AllUsers |
Where-Object { $appxPackages -contains $_.Name } |
Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue | Out-Null
# Legacy Windows Features & Apps
Get-WindowsCapability -Online |
Where-Object { $capabilities -contains ($_.Name -split '~')[0] } |
Remove-WindowsCapability -Online -ErrorAction SilentlyContinue | Out-Null
# Calls specified functions
Show-Header
Set-AppsRegistry
Uninstall-OneDrive
Show-Header
Disable-Recall
Show-Header
Write-Host "Pre-installed Apps and Features removed successfully." -BackgroundColor Green
Wait-IfNotSpecialize
}
else {
Show-MainMenu
}
}
# End of Software & Apps Functions
# Start of Privacy & Security Functions
# Check if Windows Defender is Enabled or Disabled
function Get-WindowsDefenderStatus {
Clear-Host
$defenderKey = "HKLM:\SYSTEM\CurrentControlSet\Services\Sense"
$defenderStatus = (Get-ItemProperty -Path $defenderKey -Name Start).Start
if ($defenderStatus -eq 4) {
Show-Header
Write-Host "Windows Defender is permanently disabled." -ForegroundColor Red
Write-Host "Press 1 to enable Windows Defender."
Write-Host "Note: Enabling Defender using this script means it cannot be permanently disabled again without reinstalling Windows with the UnattendedWinstall XML file."
$choice = Read-Host "Enter your choice (1 to enable, any other key to cancel)"
if ($choice -eq '1') {
$confirm = Read-Host "Are you sure you want to enable Windows Defender? (y/n)"
if ($confirm -eq 'y') {
Enable-WindowsDefender
}
else {
Show-MainMenu
}
}
else {
Show-MainMenu
}
}
else {
Show-Header
Write-Host "Windows Defender is already enabled. No action is needed." -ForegroundColor Green
Write-Host "Press any key to go back to the main menu."
Read-Host
Show-MainMenu
}
}
# Function to Enable Windows Defender
function Enable-WindowsDefender {
$MultilineComment = @"
Windows Registry Editor Version 5.00
; Enables Windows Defender to start in Windows Security
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Sense]
"Start"=dword:00000003
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WdBoot]
"Start"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WdFilter]
"Start"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WdNisDrv]
"Start"=dword:00000003
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WdNisSvc]
"Start"=dword:00000003
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinDefend]
"Start"=dword:00000002
"@
Set-Content -Path "$env:TEMP\Enable_Windows_Defender.reg" -Value $MultilineComment -Force
$path = "$env:TEMP\Enable_Windows_Defender.reg"
(Get-Content $path) -replace "\?", "$" | Out-File $path
Regedit.exe /S "$env:TEMP\Enable_Windows_Defender.reg"
Write-Host "Windows Defender has been enabled." -ForegroundColor Green
Write-Host "Press any key to return to the main menu."
Read-Host
}
# Check if User Account Control is Enabled or Disabled
function Get-UACStatus {
Clear-Host
$uacKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
# Get the EnableLUA and ConsentPromptBehaviorAdmin values
$uacStatus = (Get-ItemProperty -Path $uacKey -Name EnableLUA).EnableLUA
$promptBehavior = (Get-ItemProperty -Path $uacKey -Name ConsentPromptBehaviorAdmin).ConsentPromptBehaviorAdmin
# Determine if UAC is disabled based on both keys
if ($uacStatus -eq 0 -or $promptBehavior -eq 0) {
Show-Header
Write-Host "User Account Control (UAC) is currently disabled." -ForegroundColor Red
Write-Host "1. Enable UAC"
}
else {
Show-Header
Write-Host "User Account Control (UAC) is currently enabled." -ForegroundColor Green
Write-Host "1. Disable UAC"
}
Write-Host "0. Main Menu"
$choice = Read-Host "Select an option"
switch ($choice) {
1 {
$confirm = Read-Host "Are you sure you want to change UAC status? (y/n)"
if ($confirm -eq 'y') {
if ($uacStatus -eq 0) {
# Enable UAC and set the default prompt behavior
cmd.exe /c reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 1 /f 2>&1 | Out-Null
cmd.exe /c reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 2 /f 2>&1 | Out-Null
Write-Host "UAC has been enabled successfully." -ForegroundColor Green
}
else {
# Disable UAC and default prompt behavior
cmd.exe /c reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f 2>&1 | Out-Null
cmd.exe /c reg.exe add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f 2>&1 | Out-Null
Write-Host "UAC has been disabled successfully." -ForegroundColor Green
}
Write-Host "Press any key to continue."
Read-Host
Get-UACStatus
}
else {
Get-UACStatus
}
}
0 { Return }
default { Write-Host "Invalid choice. Try again."; Get-UACStatus }
}
}
# Function to Apply the Recommended Privacy Settings
function Set-RecommendedPrivacySettings {
if (-not $isSpecializePhase) {
Show-Header
Write-Host "Applying Recommended Privacy Settings . . ."
}
$MultilineComment = @"
Windows Registry Editor Version 5.00
; --Privacy and Security Settings--
; Disables Activity History
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System]
"EnableActivityFeed"=dword:00000000
"PublishUserActivities"=dword:00000000
"UploadUserActivities"=dword:00000000
; Disables Location Tracking
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location]
"Value"="Deny"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}]
"SensorPermissionState"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration]
"Status"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\Maps]
"AutoUpdateEnabled"=dword:00000000
; Disables Telemetry
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection]
"AllowTelemetry"=dword:00000000
; Disables Telemetry and Feedback Notifications
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DataCollection]
"AllowTelemetry"=dword:00000000
"DoNotShowFeedbackNotifications"=dword:00000001
; Disables Windows Ink Workspace
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\WindowsInkWorkspace]
"AllowWindowsInkWorkspace"=dword:00000000
; Disables the Advertising ID for All Users
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo]
"DisabledByGroupPolicy"=dword:00000001
; Disable Account Info
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\userAccountInformation]
"Value"="Deny"
"@
# Write the registry changes to a file and silently import it using regedit
Set-Content -Path "$env:TEMP\Recommended_Privacy_Settings.reg" -Value $MultilineComment -Force
Start-Process -FilePath "regedit.exe" -ArgumentList "/S `"$env:TEMP\Recommended_Privacy_Settings.reg`"" -NoNewWindow -Wait
if (-not $isSpecializePhase) {
Show-Header
Write-Host "Recommended Privacy Settings Applied." -ForegroundColor Green
Wait-IfNotSpecialize
}
}
# Function to Apply the Default Privacy Settings
function Set-DefaultPrivacySettings {
Show-Header
Write-Host "Applying Default Privacy Settings . . ."
$MultilineComment = @"
Windows Registry Editor Version 5.00
; --Revert Privacy and Security Settings--
; Enables Activity History
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\System]
"EnableActivityFeed"=-
"PublishUserActivities"=-
"UploadUserActivities"=-
; Enables Location Tracking
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location]
"Value"=-
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}]
"SensorPermissionState"=-
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration]
"Status"=-
[HKEY_LOCAL_MACHINE\SYSTEM\Maps]
"AutoUpdateEnabled"=dword:00000001
; Enables Telemetry to the default level
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection]
"AllowTelemetry"=-
; Enables Telemetry and Feedback Notifications
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DataCollection]
"AllowTelemetry"=-
"DoNotShowFeedbackNotifications"=-
; Enables Windows Ink Workspace
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\WindowsInkWorkspace]
"AllowWindowsInkWorkspace"=-
; Enables the Advertising ID for All Users
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\AdvertisingInfo]
"DisabledByGroupPolicy"=-
; Allow Account info
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\userAccountInformation]
"Value"="Allow"
"@
Set-Content -Path "$env:TEMP\Default_Privacy_Settings.reg" -Value $MultilineComment -Force
Regedit.exe /S "$env:TEMP\Default_Privacy_Settings.reg"
Show-Header
Write-Host "Default Privacy Settings Applied." -ForegroundColor Green
Wait-IfNotSpecialize
}
# End of Privacy and Security Functions
# Start of Windows Update Functions
function Set-RecommendedUpdateSettings {
if (-not $isSpecializePhase) {
Show-Header
Write-Host "Applying Recommended Windows Update Settings . . ."
}
$MultilineComment = @"
Windows Registry Editor Version 5.00
; --Windows Update Settings--
; Disable Automatic Updates (Only Check for Updates Manually)
; Notify Before Downloading and Installing Updates
; Enable Notifications for Security Updates Only (Do Not Auto-Download)
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU]
"NoAutoUpdate"=dword:00000001
"AUOptions"=dword:00000002
"AutoInstallMinorUpdates"=dword:00000000
; Prevent Automatic Upgrade from Windows 10 22H2 to Windows 11 (Manual Upgrade Still Allowed)
; Delay Feature and Quality updates for 1 year from install.
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetReleaseVersion"=dword:00000001
"TargetReleaseVersionInfo"="22H2"
"ProductVersion"="Windows 10"
"DeferFeatureUpdates"=dword:00000001
"DeferFeatureUpdatesPeriodInDays"=dword:0000016d
"DeferQualityUpdates"=dword:00000001
"DeferQualityUpdatesPeriodInDays"=dword:00000007
; Disables allowing downloads from other PCs (Delivery Optimization)
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DeliveryOptimization]
"DODownloadMode"=dword:00000000
"@
Set-Content -Path "$env:TEMP\Recommended_Windows_Update_Settings.reg" -Value $MultilineComment -Force
# import reg file
Regedit.exe /S "$env:TEMP\Recommended_Windows_Update_Settings.reg"
if (-not $isSpecializePhase) {
Show-Header
Write-Host "Recommended Windows Update Settings Applied." -ForegroundColor Green
Wait-IfNotSpecialize
}
}
function Set-DefaultUpdateSettings {
Show-Header
Write-Host "Applying Default Windows Update Settings . . ."
$MultilineComment = @"
Windows Registry Editor Version 5.00
; --Set Default Windows Update Settings--
; Enable Automatic Updates (Default: Automatic Download and Install)
; Set Updates to Default Behavior (Automatic Download and Install)
; Allow Automatic Installation of Minor Updates (Default: Allowed)
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU]
"NoAutoUpdate"=-
"AUOptions"=-
"AutoInstallMinorUpdates"=-
; --Revert Windows 10 22H2 Auto Upgrade to 11 Block to Default--
; Allow Feature and Quality updates
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetReleaseVersion"=-
"TargetReleaseVersionInfo"=-
"ProductVersion"=-
"DeferFeatureUpdates"=-
"DeferFeatureUpdatesPeriodInDays"=-
"DeferQualityUpdates"=dword:-
"DeferQualityUpdatesPeriodInDays"=-
; Reverts Delivery Optimization settings to allow downloads from other PCs
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\DeliveryOptimization]
"DODownloadMode"=-
"@
Set-Content -Path "$env:TEMP\Default_Windows_Update_Settings.reg" -Value $MultilineComment -Force
Regedit.exe /S "$env:TEMP\Default_Windows_Update_Settings.reg"
Show-Header
Write-Host "Default Windows Update Settings Applied." -ForegroundColor Green
Wait-IfNotSpecialize
}
# End of Windows Update Functions
# Start of Registry Optimizations
function Set-RecommendedHKLMRegistry {
# Create Registry Keys
$MultilineComment = @"
Windows Registry Editor Version 5.00
; Adds "Take Ownership" to the Right Click Context Menu for All Users
[-HKEY_CLASSES_ROOT\*\shell\TakeOwnership]
[-HKEY_CLASSES_ROOT\*\shell\runas]
[HKEY_CLASSES_ROOT\*\shell\TakeOwnership]
@="Take Ownership"
"Extended"=-
"HasLUAShield"=""
"NoWorkingDirectory"=""
"NeverDefault"=""
[HKEY_CLASSES_ROOT\*\shell\TakeOwnership\command]
@="powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l & pause' -Verb runAs\""
"IsolatedCommand"= "powershell -windowstyle hidden -command \"Start-Process cmd -ArgumentList '/c takeown /f \\\"%1\\\" && icacls \\\"%1\\\" /grant *S-1-3-4:F /t /c /l & pause' -Verb runAs\""
[HKEY_CLASSES_ROOT\Directory\shell\TakeOwnership]
@="Take Ownership"
"AppliesTo"="NOT (System.ItemPathDisplay:=\"C:\\Users\" OR System.ItemPathDisplay:=\"C:\\ProgramData\" OR System.ItemPathDisplay:=\"C:\\Windows\" OR System.ItemPathDisplay:=\"C:\\Windows\\System32\" OR System.ItemPathDisplay:=\"C:\\Program Files\" OR System.ItemPathDisplay:=\"C:\\Program Files (x86)\")"
"Extended"=-
"HasLUAShield"=""
"NoWorkingDirectory"=""
"Position"="middle"