|
param ( |
|
# AppX Packages to remove |
|
[Parameter(Mandatory = $false)] |
|
[string[]] $AppxTBR = @( |
|
'Clipchamp.Clipchamp' |
|
'Microsoft.BingNews' |
|
'Microsoft.BingWeather' |
|
'Microsoft.GamingApp' |
|
'Microsoft.GetHelp' |
|
'Microsoft.Getstarted' |
|
'Microsoft.MicrosoftOfficeHub' |
|
'Microsoft.MicrosoftSolitaireCollection' |
|
'Microsoft.People' |
|
'Microsoft.PowerAutomateDesktop' |
|
'Microsoft.Todos' |
|
'Microsoft.WindowsAlarms' |
|
'microsoft.windowscommunicationsapps' |
|
'Microsoft.WindowsFeedbackHub' |
|
'Microsoft.WindowsMaps' |
|
'Microsoft.WindowsSoundRecorder' |
|
'Microsoft.Xbox.TCUI' |
|
'Microsoft.XboxGamingOverlay' |
|
'Microsoft.XboxGameOverlay' |
|
'Microsoft.XboxSpeechToTextOverlay' |
|
'Microsoft.ZuneMusic' |
|
'Microsoft.ZuneVideo' |
|
'Microsoft.Windows.Ai.Copilot.Provider' |
|
'MicrosoftCorporationII.MicrosoftFamily' |
|
'MicrosoftCorporationII.QuickAssist' |
|
'MicrosoftTeams' |
|
'Microsoft.549981C3F5F10' |
|
), |
|
|
|
# Windows Capabilities to remove |
|
[Parameter(Mandatory = $false)] |
|
[string[]] $CapsTBR = @( |
|
'Microsoft.Windows.Wifi.Client.Broadcom.Bcmpciedhd63' |
|
'Microsoft.Windows.Wifi.Client.Broadcom.Bcmwl63al' |
|
'Microsoft.Windows.Wifi.Client.Broadcom.Bcmwl63a' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwbw02' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwew00' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwew01' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwlv64' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwns64' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwsw00' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwtw02' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwtw04' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwtw06' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwtw08' |
|
'Microsoft.Windows.Wifi.Client.Intel.Netwtw10' |
|
'Microsoft.Windows.Wifi.Client.Marvel.Mrvlpcie8897' |
|
'Microsoft.Windows.Wifi.Client.Qualcomm.Athw8x' |
|
'Microsoft.Windows.Wifi.Client.Qualcomm.Athwnx' |
|
'Microsoft.Windows.Wifi.Client.Qualcomm.Qcamain10x64' |
|
'Microsoft.Windows.Wifi.Client.Ralink.Netr28x' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtl8187se' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtl8192se' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtl819xp' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtl85n64' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtwlane01' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtwlane13' |
|
'Microsoft.Windows.Wifi.Client.Realtek.Rtwlane' |
|
'Microsoft.Windows.Ethernet.Client.Intel.E1i68x64' |
|
'Microsoft.Windows.Ethernet.Client.Intel.E2f68' |
|
'Microsoft.Windows.Ethernet.Client.Realtek.Rtcx21x64' |
|
'Microsoft.Windows.Ethernet.Client.Vmware.Vmxnet3' |
|
'App.StepsRecorder' |
|
'Brower.InternetExplorer' |
|
'Hello.Face' |
|
'Language.Handwriting' |
|
'Language.OCR' |
|
'Language.Speech' |
|
'Language.TextToSpeech' |
|
'MathRecognizer' |
|
'Media.WindowsMediaPlayer' |
|
'Microsoft.Wallpapers.Extended' |
|
# 'Microsoft.Windows.PowerShell.ISE' # IDK, but access denied |
|
), |
|
|
|
# Windows Capabilities to add |
|
[Parameter(Mandatory = $false)] |
|
[string[]] $CapsTBA = @(), |
|
|
|
# Optioanl Features to disable |
|
[Parameter(Mandatory = $false)] |
|
[string[]] $WOFsTBD = @( |
|
'Printing-PrintToPDFServices-Features' |
|
'SearchEngine-Client-Package' |
|
'WorkFolders-Client' |
|
'MediaPlayback' |
|
'WindowsMediaPlayer' |
|
# 'SmbDirect' |
|
), |
|
|
|
# Optional Features to enable |
|
[Parameter(Mandatory = $false)] |
|
[string[]] $WOFsTBE = @( |
|
# 'NetFX3', # .NET 3.5. Uncomment if you want to enable this |
|
), |
|
|
|
<# |
|
****############################################################################ |
|
****############################################################################ |
|
****##################### ##################### |
|
****##################### DO NOT EDIT AFTER THIS LINE !! ##################### |
|
****##################### ##################### |
|
****############################################################################ |
|
****############################################################################ |
|
#> |
|
|
|
# Additional AppX Packages to remove |
|
[Parameter(Mandatory = $false)] [Alias("rp")] |
|
[string[]] $RemovePackage, |
|
|
|
# Additional Windows Capabilities to add |
|
[Parameter(Mandatory = $false)] [Alias("wc", "cap", "Capability", "WindowsCapability")] |
|
[string[]] $AddCapability, |
|
|
|
# Additional Windows Capabilities to remove |
|
[Parameter(Mandatory = $false)] [Alias("rc")] |
|
[string[]] $RemoveCapability, |
|
|
|
# Additional Optional Features to enable |
|
[Parameter(Mandatory = $false)] [Alias("of", "wof", "Feature", "OptionalFeature")] |
|
[string[]] $EnableFeature, |
|
|
|
# Additional Optional Features to disable |
|
[Parameter(Mandatory = $false)] [Alias("rf", "rof")] |
|
[string[]] $DisableFeature, |
|
|
|
# Whether to print logs in realtime |
|
[Parameter(Mandatory = $false)] |
|
[switch] $Log, |
|
|
|
[Parameter(Mandatory = $false)] |
|
[switch] $DebugTrace, |
|
[Parameter(Mandatory = $false)] |
|
[int] $StartDebugAt, |
|
[Parameter(Mandatory = $false)] |
|
[int] $StopDebugAt, |
|
|
|
# Whether to skip every prompt |
|
[Parameter(Mandatory = $false)] |
|
[switch] $y |
|
) |
|
|
|
if ($DebugTrace) { Set-PSDebug -Trace 1 } |
|
if ($Log) { $InformationPreference = 'Continue' } |
|
$ErrorActionPreference = "Stop" |
|
|
|
<# |
|
############################################################################### |
|
[ CHECK AND RUN THE SCRIPT AS ADMINISTRATOR IF REQUIRED ] |
|
############################################################################### |
|
#> |
|
{ |
|
$adminSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544") |
|
$script:admins = $adminSID.Translate([System.Security.Principal.NTAccount]) |
|
$winID = [System.Security.Principal.WindowsIdentity]::GetCurrent() |
|
$winPrincipal = New-Object System.Security.Principal.WindowsPrincipal($winID) |
|
if (!$winPrincipal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) |
|
{ |
|
Write-Success "Restarting terminal as admin in a new window, you can close this one." |
|
$sudo = New-Object System.Diagnostics.ProcessStartInfo("PowerShell") |
|
$sudo.Arguments = $minvocation.MyCommand.Definition |
|
$sudo.Verb = "runAs" |
|
[System.Diagnostics.Process]::Start($sudo) |
|
exit 0 |
|
} |
|
}.Invoke() |
|
|
|
<# |
|
############################################################################### |
|
[ CHECK IF THE OPTION IS CORRECT ] |
|
############################################################################### |
|
#> |
|
if (!$y) { |
|
Clear-Host |
|
$warnMessage = " |
|
The Micro11 Post Applier is a script that applies optimization |
|
that applies to Micro11 to Windows PCs that are already installed, |
|
where possible. Scripts may not work as normal because each version and |
|
installed edition may have different ways of operating, |
|
Scripts approach the system directly and apply modifications, |
|
which can damage the system. |
|
|
|
It is recommended that you download all the drivers because they are removed from the system, |
|
Back up Windows first for unexpected situations. |
|
|
|
Are you sure you want to continue? [y/N] |
|
" |
|
if (0 -ne (Read-Choices "WARNING! This script can damage your computer!" -Content $warnMessage -Default 1)) { |
|
Clear-Host |
|
Write-Warning "The script was interrupted because an invalid key was entered or the user ordered cancellation." |
|
Write-Error "The script could not continue. The script is terminated." |
|
exit 0 |
|
} |
|
$warnMessage = " |
|
If you haven't installed the driver yourself, check your network controller |
|
in Device Manager and install the driver first. |
|
|
|
If you have already installed the driver, type 'N' to move to the next step. |
|
" |
|
if (0 -ne (Read-Choices "This script will remove the wired/wireless Ethernet drivers built into Windows!" -Content $warnMessage -Choice '&Next', '&Cancel' -Default 1)) { |
|
Clear-Host |
|
Write-Warning "The script was interrupted because an invalid key was entered or the user ordered cancellation." |
|
Write-Error "The script could not continue. The script is terminated." |
|
exit 0 |
|
} |
|
Write-Status "Off we go..." |
|
Start-Sleep -Seconds 2 |
|
Clear-Host |
|
} |
|
|
|
<# |
|
############################################################################### |
|
[ START THE TRANSCRIPT AND PREPARE THE ENVIRONMENT ] |
|
############################################################################### |
|
#> |
|
|
|
$Host.UI.RawUI.WindowTitle = "Micro11 Post Applier" |
|
|
|
try { Start-Transcript -Path "$pwd\post11.log" } |
|
catch { |
|
if ($_.FullyQualifiedErrorId -ne "CannotStartTranscription,Microsoft.PowerShell.Commands.StartTranscriptCommand") { |
|
throw $_ |
|
} |
|
|
|
Start-Transcript -Path "$pwd\post11.log" |
|
} |
|
|
|
$FSAR = New-Object System.Security.AccessControl.FileSystemAccessRule($admins, "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow") |
|
$regAR = New-Object System.Security.AccessControl.RegistryAccessRule($admins, "FullControl", "ContainerInherit", "None", "Allow") |
|
|
|
$Step = 0 |
|
|
|
Clear-Host |
|
|
|
<# |
|
############################################################################### |
|
[ ASK FOR ADDITIONAL OPTION EDIT ] |
|
############################################################################### |
|
#> |
|
$AppxTBR += $RemovePackage |
|
$CapsTBA += $AddCapability |
|
$CapsTBR += $RemoveCapability |
|
$WOFsTBE += $EnableFeature |
|
$WOFsTBD += $DisableFeature |
|
|
|
Invoke-Safely -When { !$y } "Ask for additional option edit" { |
|
if (0 -ne (Read-Choices "Do you want to modify the build options?")) { return } |
|
|
|
Write-Status "Loading system package configuration... Please wait" |
|
$availablePkgs = Get-ProvisionedAppxPackage -Online |
|
$availableCaps = Get-WindowsCapability -Online |
|
$installedCaps = $availableCaps | Where-Object { 'Installed' -eq $_.State } |
|
$installableCaps = $availableCaps | Where-Object { 'NotPresent' -eq $_.State } |
|
$availableWOFs = Get-WindowsOptionalFeature -Online |
|
$enabledWOFs = $availableWOFs | Where-Object { 'Enabled' -eq $_.State } |
|
$disabledWOFs = $availableWOFs | Where-Object { 'Disabled' -eq $_.State } |
|
Write-Success "Load complete!" |
|
|
|
$promptRemPkgs = { |
|
Write-Status "Please enter the provisioned packages that you want to remove." -Success |
|
Write-Host "Separate them with spaces." |
|
Write-Host " " |
|
Write-Notify "Currently available provisioned packages are:" |
|
$availablePkgs | Format-Wide -Property DisplayName -AutoSize | Out-Host |
|
Write-Host "Don't do anything until you see the prompt!" -ForegroundColor DarkYellow |
|
$script:AppxTBR = @(Read-Prompts "Packages to remove" -DefaultValue "$AppxTBR") |
|
} |
|
|
|
$promptAddCaps = { |
|
Write-Status "Please enter the Windows Capabilities you want to add." -Success |
|
Write-Host "Separate them with spaces." |
|
Write-Host " " |
|
Write-Notify "Currently available Windows Capabilities are:" |
|
$installableCaps | Format-Wide -Property Name -AutoSize | Out-Host |
|
Write-Host "Don't do anything until you see the prompt!" -ForegroundColor DarkYellow |
|
$script:CapsTBA = @(Read-Prompts "Capabilities to add" -DefaultValue "$CapsTBA") |
|
} |
|
|
|
$promptRemCaps = { |
|
Write-Status "Please enter the Windows Capabilities you want to remove." -Success |
|
Write-Host "Separate them with spaces." |
|
Write-Host " " |
|
Write-Notify "Currently available Windows Capabilities are:" |
|
$installedCaps | Format-Wide -Property Name -AutoSize | Out-Host |
|
Write-Host "Don't do anything until you see the prompt!" -ForegroundColor DarkYellow |
|
$script:CapsTBR = @(Read-Prompts "Capabilities to remove" -DefaultValue "$CapsTBR") |
|
} |
|
|
|
$promptWOFsON = { |
|
Write-Status "Please enter the Optional Features you want to enable." -Success |
|
Write-Host "Separate them with spaces." |
|
Write-Host " " |
|
Write-Notify "Currently available Optional Features are:" |
|
$disabledWOFs | Format-Wide -Property FeatureName -AutoSize | Out-Host |
|
Write-Host "Don't do anything until you see the prompt!" -ForegroundColor DarkYellow |
|
$script:WOFsTBE = @(Read-Prompts "Features to enable" -DefaultValue "$WOFsTBE") |
|
} |
|
|
|
$promptWOFsOFF = { |
|
Write-Status "Please enter the Optional Features you want to disable." -Success |
|
Write-Host "Separate them with spaces." |
|
Write-Host " " |
|
Write-Notify "Currently available Optional Features are:" |
|
$enabledWOFs | Format-Wide -Property FeatureName -AutoSize | Out-Host |
|
Write-Host "Don't do anything until you see the prompt!" -ForegroundColor DarkYellow |
|
$script:WOFsTBD = @(Read-Prompts "Features to disable" -DefaultValue "$WOFsTBD") |
|
} |
|
|
|
while ($true) { |
|
Clear-Host |
|
Write-Notify "AppX Packages to be removed" |
|
Write-Host "$AppxTBR" |
|
Write-Notify "Windows Capabilities to be added" |
|
Write-Host "$CapsTBA" |
|
Write-Notify "Windows Capabilities to be removed" |
|
Write-Host "$CapsTBR" |
|
Write-Notify "Optional Features to be enabled" |
|
Write-Host "$WOFsTBE" |
|
Write-Notify "Optional Packages to be disabled" |
|
Write-Host "$WOFsTBD" |
|
switch ( |
|
Read-Choices "Select the value you want to modify. Confirm as 'C'." ` |
|
-Choice '&Packages to Remove', 'Capabilities to &Add', 'Capabilities to &Remove', 'Features to &Enable', 'Features to &Disable', '&Confirm' ` |
|
-Default 5 |
|
) { |
|
0 { $promptRemPkgs.Invoke() } |
|
1 { $promptAddCaps.Invoke() } |
|
2 { $promptRemCaps.Invoke() } |
|
3 { $promptWOFsON.Invoke() } |
|
4 { $promptWOFsOFF.Invoke() } |
|
5 { return } |
|
} |
|
} |
|
} |
|
$AppxTBR = $AppxTBR.Split(' ') |
|
$CapsTBA = $CapsTBA.Split(' ') |
|
$CapsTBR = $CapsTBR.Split(' ') |
|
$WOFsTBE = $WOFsTBE.Split(' ') |
|
$WOFsTBD = $WOFsTBD.Split(' ') |
|
|
|
<# |
|
############################################################################### |
|
[ REMOVE PROVISIONED BLOATWARE PACKAGES & CAPABILITIES ] |
|
############################################################################### |
|
#> |
|
Invoke-Safely -Id (++$Step) "Remove provisioned bloatware packages, capabilities and features" { |
|
$activity = "Performing removal of packages..."; Write-Status $activity |
|
|
|
$init = Get-Date; $jid = Lock-Random; $task = "Getting ready..."; $pass = 1 |
|
$size = ($AppxTBR.Count + $CapsTBR.Count + $CapsTBA.Count + $WOFsTBD.Count + $WOFsTBE.Count + 1) * 100 |
|
$update = { |
|
$j = Start-Job $args[1] |
|
while ('Completed' -ne $j.State) { |
|
if ('Failed' -eq $j.State) { throw ($j.Error) } |
|
$working = $j.ChildJobs[0].Progress.PercentComplete | Select-Last |
|
if ("$null" -ne "$working") { $display = "($working% complete)" } |
|
$current = ($pass + $working) / $size; $percent = $current * 100 | Round |
|
$elapsed = ((Get-Date) - $init).TotalSeconds |
|
Write-Progress -Id $jid ` |
|
-Activity "Performing removal of packages..." ` |
|
-Status "$task ($percent% Complete)" ` |
|
-CurrentOperation "$($args[0]) $display" ` |
|
-PercentComplete $percent ` |
|
-SecondsRemaining (($elapsed / $current) - $elapsed) |
|
} |
|
} |
|
$initializing = { |
|
$current = $pass / $size; $percent = $current * 100 | Round |
|
$elapsed = ((Get-Date) - $init).TotalSeconds |
|
Write-Progress -Id $jid ` |
|
-Activity "Performing removal of packages..." ` |
|
-Status "$task ($percent% Complete)" ` |
|
-CurrentOperation $args[0] ` |
|
-PercentComplete $percent ` |
|
-SecondsRemaining (($elapsed / $current) - $elapsed) |
|
} |
|
|
|
Write-Progress -Id $jid -Activity "Performing removal of packages..." -Status $task -PercentComplete 0 |
|
Start-Sleep -Seconds 2 |
|
|
|
$task = "Removing provisioned packages..."; $initializing.Invoke("Reading packages...") |
|
$availablePkgs = Write-Result { Get-ProvisionedAppxPackage -Online } |
|
if ($AppxTBR) { |
|
$list = $availablePkgs.PackageName |
|
forEach ($appx in $AppxTBR) { |
|
$match = $list | Where-Object { $_ -like "$appx*" } | Select-Last |
|
if (("$null" -ne "$appx") -and ("$null" -ne "$match")) |
|
{ |
|
Write-Operation "Remove provisioned Appx package" -Target "$match" |
|
$update.Invoke("Removing $appx", { Remove-ProvisionedAppxPackage -Online -PackageName "$using:match" }) |
|
} |
|
$pass += 100 |
|
} |
|
} |
|
|
|
$task = "Removing unnecessary capabilities..."; $initializing.Invoke("Reading capabilities...") |
|
$availableCaps = Write-Result { Get-WindowsCapability -Online } |
|
if ($CapsTBR) { |
|
$list = ($availableCaps | Where-Object { $_.State -eq 'Installed' }).Name |
|
forEach ($cap in $CapsTBR) { |
|
$match = $list | Where-Object { $_ -like "$cap*" } | Select-Last |
|
if (("$null" -ne "$cap") -and ("$null" -ne "$match")) |
|
{ |
|
Write-Operation "Remove Windows capability" -Target "$match" |
|
$update.Invoke("Removing $cap", { Remove-WindowsCapability -Online -Name "$using:match" }) |
|
} |
|
$pass += 100 |
|
} |
|
} |
|
if ($CapsTBA) { |
|
$list = ($availableCaps | Where-Object { $_.State -eq 'NotPresent' }).Name |
|
forEach ($cap in $CapsTBA) { |
|
$match = $list | Where-Object { $_ -like "$cap*" } | Select-Last |
|
if (("$null" -ne "$cap") -and ("$null" -ne "$match")) |
|
{ |
|
Write-Operation "Add new Windows capability" -Target "$match" |
|
$update.Invoke("Adding $cap", { Add-WindowsCapability -Online -Name "$using:match" }) |
|
} |
|
$pass += 100 |
|
} |
|
} |
|
|
|
$task = "Disabling unnecessary features..."; $initializing.Invoke("Reading optional features...") |
|
$availableWOFs = Write-Result { Get-WindowsOptionalFeature -Online } |
|
if ($WOFsTBD) { |
|
$list = ($availableWOFs | Where-Object { $_.State -eq 'Enabled' }).FeatureName |
|
forEach ($wof in $WOFsTBD) { |
|
$match = $list | Where-Object { $_ -eq $wof } |
|
if (("$null" -ne "$wof") -and ("$null" -ne "$match")) |
|
{ |
|
Write-Operation "Disable Windows Optional Feature" -Target "$match" |
|
$update.Invoke("Disabling $wof", { Disable-WindowsOptionalFeature -Online -FeatureName "$using:match" -NoRestart }) |
|
} |
|
$pass += 100 |
|
} |
|
} |
|
if ($WOFsTBE) { |
|
$list = ($availableWOFs | Where-Object { $_.State -eq 'Disabled' }).FeatureName |
|
forEach ($wof in $WOFsTBE) { |
|
$match = $list | Where-Object { $_ -eq $wof } |
|
if (("$null" -ne "$wof") -and ("$null" -ne "$match")) |
|
{ |
|
Write-Operation "Enable Windows Optional Feature" -Target "$match" |
|
$update.Invoke("Enabling $wof", { Enable-WindowsOptionalFeature -Online -FeatureName "$using:match" -NoRestart }) |
|
} |
|
$pass += 100 |
|
} |
|
} |
|
|
|
Write-Progress -Id $jid -Activity $activity -Status "Done." -Completed |
|
Write-Success "Removal complete!" |
|
Unlock-Random $jid |
|
} |
|
Invoke-Safely -Id (++$Step) "Removing microsoft's spyware" { |
|
Write-Status "Removing MSEdge & OneDrive..." |
|
$msedge = @( |
|
"$Env:SystemDrive\Program Files (x86)\Microsoft\Edge", |
|
"$Env:SystemDrive\Program Files (x86)\Microsoft\EdgeCore", |
|
"$Env:SystemDrive\Program Files (x86)\Microsoft\EdgeUpdate" |
|
) |
|
if (Test-Paths -Path $msedge -Or) { |
|
Write-Host "Removing Edge..." |
|
Remove-ItemWithProgress -Path $msedge > $null |
|
} else { |
|
Write-Warning "Can't find Microsoft Edge, skipping delete" |
|
} |
|
|
|
$webview = "$Env:SystemDrive\Windows\System32\Microsoft-Edge-Webview" |
|
if (Test-Path -Path $webview) { |
|
Write-Host "Removing Edge WebView..." |
|
Remove-ItemWithProgress -Path $webview -AccessRule $FSAR > $null |
|
} else { |
|
Write-Warning "Can't find Microsoft Edge WebView, skipping delete" |
|
} |
|
|
|
$webviewSxS = (Get-ChildItem -Path "$Env:SystemDrive\Windows\WinSxS" -Filter "$($arch)_microsoft-edge-webview_31bf3856ad364e35*" -Directory).FullName |
|
if ($webviewSxS) { |
|
Write-Host "Removing System WebView..." |
|
Remove-ItemWithProgress -Path $webviewSxS -AccessRule $FSAR > $null |
|
} else { |
|
Write-Warning "Can't find System WebView, skipping delete" |
|
} |
|
|
|
$drive = @( |
|
"$Env:SystemDrive\Windows\System32\OneDriveSetup.exe" |
|
"$Env:SystemDrive\Windows\SysWOW64\OneDriveSetup.exe" |
|
"$Env:SystemDrive\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\OneDrive.lnk" |
|
) |
|
if (Test-Paths -Path $drive -Or) { |
|
Write-Host "Removing OneDrive..." |
|
Remove-ItemWithProgress -Path $drive -AccessRule $FSAR > $null |
|
} else { |
|
Write-Warning "Can't find Microsoft Edge, skipping delete" |
|
} |
|
|
|
Write-Success "Removal complete!" |
|
} |
|
Invoke-Safely -Id (++$Step) "Optimize answerfile" { |
|
Write-Status "Optimizing answerfile..." |
|
Invoke-WebRequest ` |
|
-Uri "https://gist.githubusercontent.com/AlphaKR93/73aadf32a18507dda310bf1e7d871178/raw/autounattend.xml" ` |
|
-OutFile "$Env:SystemDrive\Windows\System32\Sysprep\autounattend.xml" |
|
Write-Success "Optimized answerfile!" |
|
} |
|
|
|
<# |
|
############################################################################### |
|
[ APPLY OPTIMIZATIONS TO THE REGISTRY ] |
|
############################################################################### |
|
#> |
|
$takeReg = { |
|
$regKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($args[0], [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree, [System.Security.AccessControl.RegistryRights]::TakeOwnership) |
|
$regACL = $regKey.GetAccessControl() |
|
$regACL.SetOwner($args[1]) |
|
$regKey.SetAccessControl($regACL) |
|
$regKey.Close() |
|
$regKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($args[0], [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree, [System.Security.AccessControl.RegistryRights]::ChangePermissions) |
|
$regACL = $regKey.GetAccessControl() |
|
$regACL.SetAccessRule($regAR) |
|
$regKey.SetAccessControl($regACL) |
|
$regKey.Close() |
|
} |
|
Invoke-Safely -Id (++$Step) "Perform scheduled task cleanup" { |
|
<# $regTask = @( |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{4738DE7A-BCC1-4E2D-B1B0-CADB044BFA81}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{6FAC31FA-4A85-4E64-BFD5-2154FF4594B3}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{FC931F16-B50A-472E-B061-B6F79A71EF59}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{0600DD45-FAF2-4131-A006-0B17509B9F78}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{0671EB05-7D95-4153-A32B-1426B9FE61DB}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{87BF85F4-2CE1-4160-96EA-52F554AA28A2}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{8A9C643C-3D74-4099-B6BD-9C6D170898B1}" |
|
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\{E3176A65-4E44-4ED3-AA73-3283660ACB9C}" |
|
) #> |
|
$targets = @( |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Customer Experience Improvement Program' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Power Efficiency Diagnostics' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Shell\FamilySafetyMonitor' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Shell\FamilySafetyRefresh' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Shell\FamilySafetyUpload' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Application Experience' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\AppID\SmartScreenSpecific' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Autochk' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\NetTrace' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\PI\Sqm-Tasks' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\FileHistory' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\DiskFootprint\Diagnostics' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\CloudExperienceHost' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Windows Error Reporting' |
|
'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\Management\Provisioning\Logon' |
|
) | Where-Object { Test-Path -Path $_ } | ForEach-Object { Get-ChildItem -Path $_ } |
|
$ids = ($targets | ForEach-Object { Get-ItemProperty -Path ($_ -replace 'HKEY_LOCAL_MACHINE', 'HKLM:') }).Id |
|
|
|
$filterName = { (Get-ChildItem -Path $args[0]).Name -replace (($args[0] -replace '\\', '\\') -replace 'HKLM:', 'HKEY_LOCAL_MACHINE'), '' } |
|
$removeThem = { $l = $args; $l[0] | Where-Object { $_ -in $ids } | ForEach-Object { |
|
Write-Operation "Remove Registry Key" -Target $_ |
|
try { |
|
Remove-Item -Path "$($l[1])$_" -Force |
|
} catch { |
|
Write-Warning "Cannot remove $_, skipping delete" |
|
} |
|
} } |
|
$clearEvery = { |
|
$takeReg.Invoke(($args[0] -replace 'HKLM:\\', ''), $admins) |
|
$removeThem.Invoke($filterName.Invoke($args[0]), $args[0]) |
|
} |
|
|
|
Set-Privilege SeTakeOwnershipPrivilege > $null |
|
$clearEvery.Invoke('HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Boot\') |
|
$clearEvery.Invoke('HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Plain\') |
|
$clearEvery.Invoke('HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Logon\') |
|
$clearEvery.Invoke('HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\') |
|
$clearEvery.Invoke('HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Maintenance\') |
|
} |
|
Invoke-Safely -Id (++$Step) "Apply optimizations to registry" { |
|
Write-Status "Mounting registry hives..." |
|
Write-Result { & 'reg' 'load' "HKU\NT_DEFAULT" "$Env:SystemDrive\Users\Default\ntuser.dat" } > $null |
|
New-PSDrive -Name 'HKU' -PSProvider 'Registry' -Root 'HKEY_USERS' |
|
Start-Sleep -Seconds 2 |
|
|
|
Write-Status "Optimizing registry..."; Write-Linebreak 10 |
|
|
|
$init = Get-Date; $jid = Lock-Random; $task = "Getting ready..."; $pass = 1 |
|
$update = { |
|
$current = (++$pass) / $size; $percent = $current * 100 | Round |
|
$elapsed = ((Get-Date) - $init).TotalSeconds |
|
Write-Progress -Id $jid ` |
|
-Activity "Modifying registry keys..." ` |
|
-Status "$task ($percent% Complete)" ` |
|
-CurrentOperation $args[0] ` |
|
-PercentComplete $percent ` |
|
-SecondsRemaining (($elapsed / $current) - $elapsed) |
|
} |
|
$initializing = { Write-Progress -Id $jid -Activity "Modifying registry keys..." -Status $task } |
|
|
|
$task = "Counting all registry to be modified..."; $initializing.Invoke() |
|
$regRequire = @( |
|
@{Path = "HKU:\NT_DEFAULT\Control Panel\UnsupportedHardwareNotificationCache"; Name = 'SV1'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\NT_DEFAULT\Control Panel\UnsupportedHardwareNotificationCache"; Name = 'SV2'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Control Panel\UnsupportedHardwareNotificationCache"; Name = 'SV1'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Control Panel\UnsupportedHardwareNotificationCache"; Name = 'SV2'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\OOBE"; Name = 'BypassNRO'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\MoSetup"; Name = 'AllowUpgradesWithUnsupportedTPMOrCPU'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassCPUCheck'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassRAMCheck'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassSecureBootCheck'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassStorageCheck'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassTPMCheck'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\Setup\LabConfig"; Name = 'BypassDiskCheck'; Type = 'DWORD'; Data = '1'} |
|
) |
|
$regSponsorAdd = @( |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; Name = 'ShowSyncProviderNotifications'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement"; Name = 'ScoobeSystemSettingsEnabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SoftLandingEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'ContentDeliveryAllowed'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'FeatureManagementEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SilentInstalledAppsEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SystemPaneSuggestionsEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'PreInstalledAppsEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'PreInstalledAppsEverEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'OEMPreInstalledAppsEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContentEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-338387Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-310093Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-338388Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-338389Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-338393Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-353694Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-353696Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\ContentDeliveryManager"; Name = 'SubscribedContent-353698Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\MRT"; Name = 'DontOfferThroughWUAU'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Dsh"; Name = 'AllowNewsAndInterests'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\PushToInstall"; Name = 'DisablePushToInstall'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer"; Name = 'HideRecommendedSection'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"; Name = 'DisableSoftLanding'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"; Name = 'DisableCloudOptimizedContent'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"; Name = 'DisableWindowsConsumerFeatures'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"; Name = 'DisableWindowsSpotlightFeatures'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent"; Name = 'DisableConsumerAccountStateContent'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start"; Name = 'ConfigureStartPins'; Type = 'STRING'; Data = '{"pinnedList": [{}]}'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start"; Name = 'ConfigureStartPins_ProviderSet'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\Start"; Name = 'ConfigureStartPins_WinningProvider'; Type = 'STRING'; Data = 'B5292708-1619-419B-9923-E5D9F3925E71'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\providers\B5292708-1619-419B-9923-E5D9F3925E71\default\Device\Start"; Name = 'ConfigureStartPins'; Type = 'STRING'; Data = '{"pinnedList": [{}]}'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\PolicyManager\providers\B5292708-1619-419B-9923-E5D9F3925E71\default\Device\Start"; Name = 'ConfigureStartPins_LastWrite'; Type = 'DWORD'; Data = '1'} |
|
) |
|
$regSponsorRem = @( |
|
"HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\Subscriptions" |
|
"HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\ContentDeliveryManager\SuggestedApps", |
|
"HKLM:\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\OutlookUpdate" |
|
"HKLM:\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe\DevHomeUpdate" |
|
) |
|
$regTelementryAdd = @( |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Input\TIPC"; Name = 'Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\InputPersonalization"; Name = 'RestrictImplicitInkCollection'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\InputPersonalization"; Name = 'RestrictImplicitTextCollection'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\InputPersonalization\TrainedDataStore"; Name = 'HarvestContacts'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Speech_OneCore\Settings\OnlineSpeechPrivacy"; Name = 'HasAccepted'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Personalization\Settings"; Name = 'AcceptedPrivacyPolicy'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\AdvertisingInfo"; Name = 'Enabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Privacy"; Name = 'TailoredExperiencesWithDiagnosticDataEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer"; Name = 'HideRecentlyAddedApps'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection"; Name = 'AllowTelemetry'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection"; Name = 'DoNotShowFeedbackNotifications'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\dmwappushservice"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
) |
|
$regChat = @( |
|
@{Path = "HKU:\.DEFAULT\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; Name = 'TaskbarMn'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Communications"; Name = 'ConfigureChatAutoInstall'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Chat"; Name = 'ChatIcon'; Type = 'DWORD'; Data = '3'} |
|
) |
|
$regBing = @( |
|
@{Path = "HKU:\.DEFAULT\Software\Policies\Microsoft\Windows\Explorer"; Name = 'ShowRunAsDifferentUserInStart'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Software\Policies\Microsoft\Windows\Explorer"; Name = 'DisableSearchBoxSuggestions'; Type = 'DWORD'; Data = '1'} |
|
) |
|
$regCopilot = @( |
|
@{Path = "HKU:\.DEFAULT\Software\Policies\Microsoft\Windows\WindowsCopilot"; Name = 'TurnOffWindowsCopilot'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"; Name = 'ShowCopilotButton'; Type = 'DWORD'; Data = '0'} |
|
) |
|
$regDriveAdd = @(@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive"; Name = 'DisableFileSyncNGSC'; Type = 'DWORD'; Data = '1'}) |
|
$regDriveRem = @(@{Path = "HKU:\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Run"; Name = "OneDriveSetup"}) |
|
$regEdge = @( |
|
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge", |
|
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge Update" |
|
) |
|
$regFileSystem = @( |
|
@{Path = "HKU:\.DEFAULT\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell"; Name = 'FolderType'; Type = 'STRING'; Data = 'NotSpecified'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\ReserveManager"; Name = 'ShippedWithReserves'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\WSearch"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\SysMain"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Control\FileSystem"; Name = 'LongPathsEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Control\FileSystem"; Name = 'NtfsMemoryUsage'; Type = 'DWORD'; Data = '2'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Control\FileSystem"; Name = 'NtfsDisable8dot3NameCreation'; Type = 'DWORD'; Data = '1'} |
|
) |
|
$regWER = @( |
|
@{Path = "HKU:\.DEFAULT\Microsoft\Windows\Windows Error Reporting"; Name = 'Disabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Microsoft\Windows\Windows Error Reporting"; Name = 'DontShowUI'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Microsoft\Windows\Windows Error Reporting"; Name = 'OobeCompleted'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Microsoft\Windows\Windows Error Reporting"; Name = 'LoggingDisabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKU:\.DEFAULT\Microsoft\Windows\Windows Error Reporting"; Name = 'DontSendAdditionalData'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting"; Name = 'Disabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting"; Name = 'DontShowUI'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting"; Name = 'OobeCompleted'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting"; Name = 'LoggingDisabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting"; Name = 'DontSendAdditionalData'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Eroror Reporting"; Name = 'Disabled'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\WerSvc"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
) |
|
$regUAC = @( |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; Name = 'EnableLUA'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; Name = 'PromptOnSecureDesktop'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"; Name = 'ConsentPromptBehaviorAdmin'; Type = 'DWORD'; Data = '3'} |
|
) |
|
$regAdds = @( |
|
@{Path = "HKU:\.DEFAULT\Control Panel\Desktop"; Name = 'JPEGImportQuality'; Type = 'DWORD'; Data = '100'} |
|
@{Path = "HKU:\.DEFAULT\Software\Microsoft\Narrator\NoRoam"; Name = 'WinEnterLaunchEnabled'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKU:\.DEFAULT\Software\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}"; Name = 'System.IsPinnedToNameSpaceTree'; Type = 'DWORD'; Data = '1'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings"; Name = 'IsContinuousInnovationOptedIn'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DriverSearching"; Name = 'SearchOrderConfig'; Type = 'DWORD'; Data = '0'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\RasMan"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Services\SstpSvc"; Name = 'Start'; Type = 'DWORD'; Data = '4'} |
|
@{Path = "HKLM:\SYSTEM\ControlSet001\Session Manager\Memory Management\PrefetchParameters"; Name = 'EnablePrefetcher'; Type = 'DWORD'; Data = '0'} |
|
) |
|
$regAddPath = @( |
|
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{645FF040-5081-101B-9F08-00AA002F954E}' |
|
) |
|
$regRems = @( |
|
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\DelegateFolders\{F5FB2C77-0E2F-4A16-A381-3E560C68BC83}' |
|
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\DelegateFolders\{F5FB2C77-0E2F-4A16-A381-3E560C68BC83}' |
|
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\DelegateFolders\{E88865EA-0E1C-4E20-9AA6-EDCD0212C87C}' |
|
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\DelegateFolders\{E88865EA-0E1C-4E20-9AA6-EDCD0212C87C}' |
|
) |
|
$size = ` |
|
$regRequire.Count ` |
|
+ $regSponsorAdd.Count ` |
|
+ $regSponsorRem.Count ` |
|
+ $regTelementryAdd.Count ` |
|
+ $regChat.Count ` |
|
+ $regBing.Count ` |
|
+ $regCopilot.Count ` |
|
+ $regDriveAdd.Count ` |
|
+ $regDriveRem.Count ` |
|
+ $regEdge.Count ` |
|
+ $regFileSystem.Count ` |
|
+ $regWER.Count ` |
|
+ $regUAC.Count ` |
|
+ $regAddPath.Count ` |
|
+ $regAdds.Count ` |
|
+ $regRems.Count + 1 |
|
Write-Notify "$size registry items will be modified." |
|
Start-Sleep -Seconds 2 |
|
|
|
Set-Privilege SeTakeOwnershipPrivilege > $null |
|
$takeReg.Invoke("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks", $admins) |
|
$takeReg.Invoke("SOFTWARE\Microsoft\Windows\CurrentVersion\Communications", $admins) |
|
|
|
$addRegPath = { |
|
$update.Invoke("Deleting $_") |
|
Write-Operation "Create Registry Key" -Target $_ |
|
New-Item -Path $_ -Force > $null |
|
} |
|
$remRegPath = { |
|
$update.Invoke("Deleting $_") |
|
if (Test-Path -Path $_) |
|
{ |
|
Write-Operation "Remove Registry Key" -Target "$_" |
|
Remove-Item -Path $_ -Force -Recurse -ErrorAction Stop |
|
} |
|
else { Write-Warning "Failed to find $_, skipping delete" } |
|
} |
|
$addRegItem = { |
|
$update.Invoke("Creating $($_.Path)\$($_.Name)") |
|
Write-Operation "Create Registry Item" -Target "Item: $($_.Path)\$($_.Name) Value: $($_.Data)" |
|
if (!(Test-Path -Path $_.Path)) |
|
{ |
|
Write-Operation "Create Registry Key" -Target $_.Path |
|
New-Item -Path $_.Path -Force > $null |
|
} |
|
New-ItemProperty -Path $_.Path -Name $_.Name -PropertyType $_.Type -Value $_.Data -Force > $null |
|
} |
|
$remRegItem = { |
|
$update.Invoke("Deleting $($_.Path)\$($_.Name)") |
|
if (Test-Path -Path "$($_.Path)\$($_.Name)") |
|
{ |
|
Write-Operation "Remove Registry Item" -Target "Item: $($_.Path)\$($_.Name)" |
|
Remove-ItemProperty -Path $_.Path -Name $_.Name -Force > $null |
|
} |
|
else { Write-Warning "Failed to find $($_.Path)\$($_.Name), skipping delete" } |
|
} |
|
|
|
$task = "Bypassing system requirements..." |
|
$regRequire | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling Sponsored Apps..." |
|
$regSponsorAdd | ForEach-Object $addRegItem |
|
$regSponsorRem | ForEach-Object $remRegPath |
|
|
|
$task = "Disabling Telementry..." |
|
$regTelementryAdd | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling Chat icon..." |
|
$regChat | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling bing search..." |
|
$regBing | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling Copilot..." |
|
$regCopilot | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling OneDrive backup..." |
|
$regDriveAdd | ForEach-Object $addRegItem |
|
$regDriveRem | ForEach-Object $remRegItem |
|
|
|
$task = "Removing Edge related keys..." |
|
$regEdge | ForEach-Object $remRegPath |
|
|
|
$task = "Tweaking FileSystem related values..." |
|
$regFileSystem | ForEach-Object $addRegItem |
|
|
|
$task = "Disabling Windows Error Reporting..." |
|
$regWER | ForEach-Object $addRegItem |
|
|
|
$task = "Tweaking User Account Control..." |
|
$regUAC | ForEach-Object $addRegItem |
|
|
|
$task = "Finishing..." |
|
$regAddPath | ForEach-Object $addRegPath |
|
$regAdds | ForEach-Object $addRegItem |
|
$regRems | ForEach-Object $remRegPath |
|
|
|
Write-Progress -Id $jid -Activity "Modifying registry keys..." -Status "Done." -Completed |
|
Unlock-Random $jid; Start-Sleep -Seconds 2 |
|
|
|
Write-Status "Unmounting registry..." |
|
[gc]::collect() |
|
Start-Sleep -Seconds 2 |
|
Write-Result { & 'reg' 'unload' "HKU\NT_DEFAULT" } > $null |
|
Remove-PSDrive -Name 'HKU' -PSProvider 'Registry' -Force > $null |
|
} |
|
Invoke-Safely "Perform cleanup" { |
|
Write-Status "Successfully applied optimization!" -Success |
|
if (!$y) { Read-Host "Press Enter to exit the script" } |
|
|
|
Write-Status "Performing cleanup..." |
|
Repair-WindowsImage -Online -StartComponentCleanup -ResetBase > $null |
|
} |
|
Stop-Transcript |
|
Clear-Host |
|
Write-Success "Successfully applied " |
|
|
|
exit |