Skip to content

Commit

Permalink
Make function Remove-ItemPropertyVerified
Browse files Browse the repository at this point in the history
- Serves to verify empty paths while removing properties from registry
  • Loading branch information
LeDragoX committed May 16, 2024
1 parent be0ffec commit c618028
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 40 deletions.
68 changes: 68 additions & 0 deletions src/lib/debloat-helper/Remove-ItemPropertyVerified.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Import-Module -DisableNameChecking "$PSScriptRoot\..\Title-Templates.psm1"

function Remove-ItemPropertyVerified() {
param (
[Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[String[]] $Path,
[Parameter(Position = 1, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[String[]] $Name,
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[String[]] $Include,
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[String[]] $Exclude,
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Switch] $Force
)

Begin {
$ScriptBlock = "Remove-ItemProperty"
$Script:TweakType = "Exp/Reg"
}

Process {
If ((Get-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\").Property -ccontains $Name) {
Write-Status -Types "-", $TweakType -Status "Removing: `"$Path>$Name`""

If ($null -ne $Path) {
$ScriptBlock += " -Path "
ForEach ($PathParam in $Path) {
$ScriptBlock += "`"$PathParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Name) {
$ScriptBlock += " -Name "
ForEach ($NameParam in $Name) {
$ScriptBlock += "`"$NameParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Include) {
$ScriptBlock += " -Include "
ForEach ($IncludeParam in $Include) {
$ScriptBlock += "`"$IncludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Exclude) {
$ScriptBlock += " -Exclude "
ForEach ($ExcludeParam in $Exclude) {
$ScriptBlock += "`"$ExcludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Force) {
$ScriptBlock += " -Force"
}

Write-Verbose "> $ScriptBlock"
Invoke-Expression "$ScriptBlock"
} Else {
Write-Status -Types "?", $TweakType -Status "The property `"$Path>$Name`" does not exist." -Warning
}
}
}
2 changes: 1 addition & 1 deletion src/lib/debloat-helper/Remove-ItemVerified.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Remove-ItemVerified() {
Write-Verbose "> $ScriptBlock"
Invoke-Expression "$ScriptBlock"
} Else {
Write-Status -Types "?", $TweakType -Status "The path `"$Path`" does not exist" -Warning
Write-Status -Types "?", $TweakType -Status "The path `"$Path`" does not exist." -Warning
}
}
}
9 changes: 3 additions & 6 deletions src/scripts/Optimize-Performance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Open-File.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Get-HardwareInfo.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Unregister-DuplicatedPowerPlan.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\utils\Individual-Tweaks.psm1"

Expand Down Expand Up @@ -68,9 +69,7 @@ function Optimize-Performance() {
If (!(Test-Path "$PathToLMPoliciesWindowsStore")) {
New-Item -Path "$PathToLMPoliciesWindowsStore" -Force | Out-Null
}
If ((Get-Item "$PathToLMPoliciesWindowsStore").GetValueNames() -like "AutoDownload") {
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsStore" -Name "AutoDownload" # [@] (2 = Disable, 4 = Enable)
}
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesWindowsStore" -Name "AutoDownload" # [@] (2 = Disable, 4 = Enable)

Write-Section "Microsoft Edge Tweaks"
Write-Caption "System and Performance"
Expand Down Expand Up @@ -124,9 +123,7 @@ function Optimize-Performance() {
Set-ItemPropertyVerified -Path "$DesktopRegistryPath" -Name "AutoEndTasks" -Type DWord -Value 1 # Default: Removed or 0

Write-Status -Types "*", $TweakType -Status "Returning 'Hung App Timeout' to default..."
If ((Get-Item "$DesktopRegistryPath").Property -contains "HungAppTimeout") {
Remove-ItemProperty -Path "$DesktopRegistryPath" -Name "HungAppTimeout"
}
Remove-ItemPropertyVerified -Path "$DesktopRegistryPath" -Name "HungAppTimeout"

Write-Status -Types "+", $TweakType -Status "Reducing mouse and keyboard hooks timeout to 1s..."
Set-ItemPropertyVerified -Path "$DesktopRegistryPath" -Name "LowLevelHooksTimeout" -Type DWord -Value 1000 # Default: Removed or 5000
Expand Down
5 changes: 2 additions & 3 deletions src/scripts/Optimize-Privacy.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\utils\Individual-Tweaks.psm1"

Expand Down Expand Up @@ -145,9 +146,7 @@ function Optimize-Privacy() {
Set-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\EventTranscriptKey" -Name "EnableEventTranscript" -Type DWord -Value $Zero

Write-Status -Types $EnableStatus[0].Symbol, $TweakType -Status "$($EnableStatus[0].Status) feedback frequency..."
If ((Test-Path "$PathToCUSiufRules\PeriodInNanoSeconds")) {
Remove-ItemProperty -Path "$PathToCUSiufRules" -Name "PeriodInNanoSeconds"
}
Remove-ItemPropertyVerified -Path "$PathToCUSiufRules" -Name "PeriodInNanoSeconds"
Set-ItemPropertyVerified -Path "$PathToCUSiufRules" -Name "NumberOfSIUFInPeriod" -Type DWord -Value $Zero

Write-Caption "Activity History"
Expand Down
9 changes: 5 additions & 4 deletions src/scripts/Register-PersonalTweaksList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Get-HardwareInfo.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Open-File.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\utils\Individual-Tweaks.psm1"

Expand Down Expand Up @@ -100,7 +101,7 @@ function Register-PersonalTweaksList() {
$preferences.Preferences[28] = 0
Set-ItemPropertyVerified -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager" -Name "Preferences" -Type Binary -Value $preferences.Preferences
} Else {
Write-Status -Types "?", $TweakType -Status "Task Manager patch not run in builds 22557+ due to bug" -Warning
Write-Status -Types "?", $TweakType -Status "Task Manager patch will not run in builds from 22557+ due to bug" -Warning
}

Write-Section "Windows Explorer Tweaks"
Expand All @@ -124,7 +125,7 @@ function Register-PersonalTweaksList() {
Set-ItemPropertyVerified -Path "$PathToCUExplorerAdvanced" -Name "HideDrivesWithNoMedia" -Type DWord -Value $Zero

Write-Status -Types "*", $TweakType -Status "Restoring Aero-Shake Minimize feature..."
Remove-ItemProperty -Path "$PathToCUExplorerAdvanced" -Name "DisallowShaking" -Force -ErrorAction SilentlyContinue
Remove-ItemPropertyVerified -Path "$PathToCUExplorerAdvanced" -Name "DisallowShaking" -Force

Write-Status -Types "+", $TweakType -Status "Setting Windows Explorer to start on This PC instead of Quick Access..."
# [@] (1 = This PC, 2 = Quick access) # DO NOT REVERT, BREAKS EXPLORER.EXE
Expand Down Expand Up @@ -235,10 +236,10 @@ function Register-PersonalTweaksList() {
Write-Section "Microsoft Edge Policies"
Write-Caption "Privacy, search and services -> Address bar and search"
Write-Status -Types "*", $TweakType -Status "Show me search and site suggestions using my typed characters..."
Remove-ItemProperty -Path "$PathToCUPoliciesEdge", "$PathToLMPoliciesEdge" -Name "SearchSuggestEnabled" -Force -ErrorAction SilentlyContinue
Remove-ItemPropertyVerified -Path "$PathToCUPoliciesEdge", "$PathToLMPoliciesEdge" -Name "SearchSuggestEnabled" -Force

Write-Status -Types "*", $TweakType -Status "Show me history and favorite suggestions and other data using my typed characters..."
Remove-ItemProperty -Path "$PathToCUPoliciesEdge", "$PathToLMPoliciesEdge" -Name "LocalProvidersEnabled" -Force -ErrorAction SilentlyContinue
Remove-ItemPropertyVerified -Path "$PathToCUPoliciesEdge", "$PathToLMPoliciesEdge" -Name "LocalProvidersEnabled" -Force

Write-Status -Types "*", $TweakType -Status "Restoring Error reporting..."
Set-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "Disabled" -Type DWord -Value 0
Expand Down
47 changes: 21 additions & 26 deletions src/utils/Individual-Tweaks.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Get-HardwareInfo.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\New-Shortcut.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\Title-Templates.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Remove-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-CapabilityState.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-ItemPropertyVerified.psm1"
Import-Module -DisableNameChecking "$PSScriptRoot\..\lib\debloat-helper\Set-OptionalFeatureState.psm1"
Expand Down Expand Up @@ -42,9 +43,9 @@ function Disable-ActivityHistory() {

function Enable-ActivityHistory() {
Write-Status -Types "*", "Privacy" -Status "Enabling Activity History..."
Remove-ItemProperty -Path $PathToLMPoliciesSystem -Name "EnableActivityFeed"
Remove-ItemProperty -Path $PathToLMPoliciesSystem -Name "PublishUserActivities"
Remove-ItemProperty -Path $PathToLMPoliciesSystem -Name "UploadUserActivities"
Remove-ItemPropertyVerified -Path $PathToLMPoliciesSystem -Name "EnableActivityFeed"
Remove-ItemPropertyVerified -Path $PathToLMPoliciesSystem -Name "PublishUserActivities"
Remove-ItemPropertyVerified -Path $PathToLMPoliciesSystem -Name "UploadUserActivities"
}

function Disable-AutomaticWindowsUpdate() {
Expand All @@ -70,12 +71,12 @@ function Disable-AutomaticWindowsUpdate() {
function Enable-AutomaticWindowsUpdate() {
Write-Status -Types "*", "WU" -Status "Enabling Automatic Download and Installation of Windows Updates..."
Write-Status -Types "*", "WU" -Status "Removing Automatic Updates policies..."
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsUpdate" -Name "AUOptions"
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsUpdate" -Name "NoAutoUpdate"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesWindowsUpdate" -Name "AUOptions"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesWindowsUpdate" -Name "NoAutoUpdate"
Write-Status -Types "*", "WU" -Status "Removing Scheduled Day policy..."
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsUpdate" -Name "ScheduledInstallDay"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesWindowsUpdate" -Name "ScheduledInstallDay"
Write-Status -Types "*", "WU" -Status "Removing Scheduled time policy..."
Remove-ItemProperty -Path "$PathToLMPoliciesWindowsUpdate" -Name "ScheduledInstallTime"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesWindowsUpdate" -Name "ScheduledInstallTime"
}

function Disable-BackgroundAppsToogle() {
Expand All @@ -92,8 +93,8 @@ function Enable-BackgroundAppsToogle() {

function Disable-ClipboardHistory() {
Write-Status -Types "-", "Privacy" -Status "Disabling Clipboard History (requires reboot!)..."
Remove-ItemProperty -Path "$PathToLMPoliciesSystem" -Name "AllowClipboardHistory"
Remove-ItemProperty -Path "$PathToCUClipboard" -Name "EnableClipboardHistory"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesSystem" -Name "AllowClipboardHistory"
Remove-ItemPropertyVerified -Path "$PathToCUClipboard" -Name "EnableClipboardHistory"
}

function Enable-ClipboardHistory() {
Expand All @@ -105,14 +106,8 @@ function Enable-ClipboardHistory() {
function Disable-ClipboardSyncAcrossDevice() {
Write-Status -Types "-", "Privacy" -Status "Disabling Clipboard across devices (must be using MS account)..."
Set-ItemPropertyVerified -Path "$PathToLMPoliciesSystem" -Name "AllowCrossDeviceClipboard" -Type DWord -Value 0
If ((Get-Item "$PathToCUClipboard").Property -contains "CloudClipboardAutomaticUpload") {
Remove-ItemProperty -Path "$PathToCUClipboard" -Name "CloudClipboardAutomaticUpload"
}

If ((Get-Item "$PathToCUClipboard").Property -contains "EnableCloudClipboard") {
Remove-ItemProperty -Path "$PathToCUClipboard" -Name "EnableCloudClipboard"
}

Remove-ItemPropertyVerified -Path "$PathToCUClipboard" -Name "CloudClipboardAutomaticUpload"
Remove-ItemPropertyVerified -Path "$PathToCUClipboard" -Name "EnableCloudClipboard"
}

function Enable-ClipboardSyncAcrossDevice() {
Expand Down Expand Up @@ -367,12 +362,12 @@ function Enable-NewsAndInterest() {

Write-Status -Types "*", "Personal" -Status "Enabling 'News and Interest' from taskbar..."
# [@] (0 = Disable, 1 = Enable)
Remove-ItemProperty -Path "$PathToLMPoliciesNewsAndInterest" -Name "EnableFeeds"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesNewsAndInterest" -Name "EnableFeeds"
}

function Disable-OldVolumeControl() {
Write-Status -Types "*", "Misc" -Status "Disabling Old Volume Control..."
Remove-ItemProperty -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\MTCUVC" -Name "EnableMtcUvc"
Remove-ItemPropertyVerified -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\MTCUVC" -Name "EnableMtcUvc"
}

function Enable-OldVolumeControl() {
Expand All @@ -389,7 +384,7 @@ function Disable-OnlineSpeechRecognition() {

function Enable-OnlineSpeechRecognition() {
Write-Status -Types "+", "Privacy" -Status "Enabling Online Speech Recognition..."
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\InputPersonalization" -Name "AllowInputPersonalization"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Policies\Microsoft\InputPersonalization" -Name "AllowInputPersonalization"
# [@] (0 = Decline, 1 = Accept)
Set-ItemPropertyVerified -Path "$PathToCUOnlineSpeech" -Name "HasAccepted" -Type DWord -Value 1
}
Expand Down Expand Up @@ -437,7 +432,7 @@ function Disable-SearchAppForUnknownExt() {

function Enable-SearchAppForUnknownExt() {
Write-Status -Types "*", "Misc" -Status "Enabling Search for App in Store for Unknown Extensions..."
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "NoUseStoreOpenWith"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "NoUseStoreOpenWith"
}

function Disable-Telemetry() {
Expand All @@ -455,10 +450,10 @@ function Disable-Telemetry() {
function Enable-Telemetry() {
Write-Status -Types "*", "Privacy" -Status "Enabling Telemetry..."
# [@] (0 = Security (Enterprise only), 1 = Basic Telemetry, 2 = Enhanced Telemetry, 3 = Full Telemetry)
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowTelemetry"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowDeviceNameInTelemetry"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry"
Remove-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowTelemetry"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name "AllowDeviceNameInTelemetry"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry"
Remove-ItemPropertyVerified -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name "AllowTelemetry"

Set-ServiceStartup -State 'Manual' -Services "DiagTrack"
Start-Service "DiagTrack"
Expand Down Expand Up @@ -534,7 +529,7 @@ function Enable-XboxGameBarDVRandMode() {
Remove-ItemVerified -Path "$PathToLMPoliciesAppGameDVR" -Recurse
Set-ItemPropertyVerified -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR" -Name "AppCaptureEnabled" -Type DWord -Value 1
Set-ItemPropertyVerified -Path "HKCU:\System\GameConfigStore" -Name "GameDVR_Enabled" -Type DWord -Value 1
Remove-ItemProperty -Path "$PathToLMPoliciesGameDVR" -Name "AllowGameDVR"
Remove-ItemPropertyVerified -Path "$PathToLMPoliciesGameDVR" -Name "AllowGameDVR"

Set-ServiceStartup -State 'Manual' -Services "BcastDVRUserService*"

Expand Down

0 comments on commit c618028

Please sign in to comment.