Checkpoint-Computer -Description "Before cleanup - Oct 25, 2025" -RestorePointType "MODIFY_SETTINGS"Get-ComputerRestorePointsc start vss
sc start swprv
vssadmin list shadowstorage<#
.SYNOPSIS
Disable Start_TrackProgs and clear (move backup) DeviceSearchCache for the current user, then restart search/explorer.
.NOTES
Save as Clear-SearchCacheAndDisableTracking.ps1
Run from an elevated PowerShell (Run as Administrator).
Example:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\Clear-SearchCacheAndDisableTracking.ps1
The script moves the cache to a timestamped backup folder under $env:LOCALAPPDATA\DeviceSearchCacheBackup_<timestamp>.
A log is written to $env:LOCALAPPDATA\DeviceSearchCacheCleanup.log
#>
function Assert-Elevated {
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Error "This script must be run as Administrator. Right-click PowerShell and choose 'Run as administrator'. Exiting."
exit 1
}
}
# Ensure script is elevated (we need to stop/start services and restart explorer)
Assert-Elevated
$logFile = Join-Path $env:LOCALAPPDATA "DeviceSearchCacheCleanup.log"
Add-Content -Path $logFile -Value "==== Starting run: $(Get-Date -Format u) ===="
# 1) Read current Start_TrackProgs (store old value)
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
try {
$oldVal = Get-ItemProperty -Path $regPath -Name "Start_TrackProgs" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Start_TrackProgs -ErrorAction SilentlyContinue
} catch {
$oldVal = $null
}
Add-Content -Path $logFile -Value "Previous Start_TrackProgs value: $($oldVal -ne $null ? $oldVal.ToString() : '<not present>')"
# 2) Set Start_TrackProgs = 0 (disable app tracking for Start/search)
try {
New-ItemProperty -Path $regPath -Name "Start_TrackProgs" -PropertyType DWord -Value 0 -Force | Out-Null
Add-Content -Path $logFile -Value "Set Start_TrackProgs = 0"
Write-Output "Set Start_TrackProgs to 0 (disabled)."
} catch {
Write-Warning "Failed to set Start_TrackProgs: $_"
Add-Content -Path $logFile -Value "Failed to set Start_TrackProgs: $_"
}
# 3) Stop Windows Search service (WSearch) to safely remove cache
$svcName = "WSearch"
try {
if (Get-Service -Name $svcName -ErrorAction SilentlyContinue) {
Write-Output "Stopping service $svcName..."
Stop-Service -Name $svcName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Add-Content -Path $logFile -Value "Stopped $svcName"
} else {
Add-Content -Path $logFile -Value "$svcName not found"
}
} catch {
Write-Warning "Could not stop $svcName: $_"
Add-Content -Path $logFile -Value "Could not stop $svcName: $_"
}
# 4) Find Microsoft.Windows.Search package folder(s) and move DeviceSearchCache to a backup folder
$packagesPath = Join-Path $env:LOCALAPPDATA "Packages"
$searchPkgs = Get-ChildItem -Path $packagesPath -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "Microsoft.Windows.Search*" }
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupRoot = Join-Path $env:LOCALAPPDATA "DeviceSearchCacheBackup_$timestamp"
New-Item -Path $backupRoot -ItemType Directory -Force | Out-Null
$foundAny = $false
foreach ($pkg in $searchPkgs) {
$cachePath = Join-Path $pkg.FullName "LocalState\DeviceSearchCache"
if (Test-Path $cachePath) {
$foundAny = $true
$dest = Join-Path $backupRoot ($pkg.Name + "_DeviceSearchCache")
try {
# Move the folder (preserves data); if Move fails, fall back to Remove-Item
Move-Item -Path $cachePath -Destination $dest -Force -ErrorAction Stop
Write-Output "Moved DeviceSearchCache from '$cachePath' to backup '$dest'"
Add-Content -Path $logFile -Value "Moved '$cachePath' -> '$dest'"
} catch {
Write-Warning "Could not move '$cachePath' (will attempt remove): $_"
Add-Content -Path $logFile -Value "Move failed for '$cachePath': $_"
try {
Remove-Item -Path $cachePath -Recurse -Force -ErrorAction Stop
Write-Output "Removed DeviceSearchCache at '$cachePath'"
Add-Content -Path $logFile -Value "Removed '$cachePath'"
} catch {
Write-Warning "Failed to remove '$cachePath': $_"
Add-Content -Path $logFile -Value "Failed to remove '$cachePath': $_"
}
}
} else {
Add-Content -Path $logFile -Value "No DeviceSearchCache at expected path: $cachePath"
}
}
if (-not $foundAny) {
Write-Output "No Microsoft.Windows.Search package folder with DeviceSearchCache was found under $packagesPath"
Add-Content -Path $logFile -Value "No DeviceSearchCache found in any Microsoft.Windows.Search package"
}
# 5) Restart Windows Search service
try {
Start-Service -Name $svcName -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Add-Content -Path $logFile -Value "Started $svcName"
Write-Output "Restarted Windows Search service ($svcName)."
} catch {
Write-Warning "Could not start $svcName: $_"
Add-Content -Path $logFile -Value "Could not start $svcName: $_"
}
# 6) Restart Explorer to refresh Start/Search UI (optionally you may prefer to sign out or reboot)
try {
Write-Output "Restarting Explorer to refresh Start/search UI..."
Add-Content -Path $logFile -Value "Restarting Explorer..."
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Start-Process explorer.exe
Add-Content -Path $logFile -Value "Explorer restarted."
} catch {
Write-Warning "Failed to restart Explorer: $_"
Add-Content -Path $logFile -Value "Failed to restart Explorer: $_"
}
# 7) Final messages and undo help
Add-Content -Path $logFile -Value "==== Completed run: $(Get-Date -Format u) ===="
Write-Output ""
Write-Output "Done. Log written to: $logFile"
if ($foundAny) {
Write-Output "DeviceSearchCache was backed up to: $backupRoot"
} else {
Write-Output "No DeviceSearchCache folders were found to back up."
}
Write-Output ""
Write-Output "Note: Windows may re-populate Top Apps / Quick searches over time if other tracking settings are enabled. You already changed Start_TrackProgs; if you want to restore the previous value run the undo command shown below."
Write-Output ""
Write-Output "Undo / restore Start_TrackProgs to previous value (run in an elevated PowerShell or a normal shell if you prefer):"
Write-Output " # To restore tracking on (set to 1):"
Write-Output " Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name 'Start_TrackProgs' -Type DWord -Value 1"
Write-Output ""
Write-Output "If you want to restore the backed-up cache (not usually needed) you can move it back from the $backupRoot folder into the original LocalState path for the relevant package and then restart WSearch and Explorer."
# (Same header/notes as before)
function Assert-Elevated {
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Error "This script must be run as Administrator. Right-click PowerShell and choose 'Run as administrator'. Exiting."
exit 1
}
}
Assert-Elevated
$logFile = Join-Path $env:LOCALAPPDATA "DeviceSearchCacheCleanup.log"
Add-Content -Path $logFile -Value "==== Starting run: $(Get-Date -Format u) ===="
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
try {
$oldVal = Get-ItemProperty -Path $regPath -Name "Start_TrackProgs" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Start_TrackProgs -ErrorAction SilentlyContinue
} catch {
$oldVal = $null
}
Add-Content -Path $logFile -Value "Previous Start_TrackProgs value: $($oldVal -ne $null ? $oldVal.ToString() : '<not present>')"
try {
New-ItemProperty -Path $regPath -Name "Start_TrackProgs" -PropertyType DWord -Value 0 -Force | Out-Null
Add-Content -Path $logFile -Value "Set Start_TrackProgs = 0"
Write-Output "Set Start_TrackProgs to 0 (disabled)."
} catch {
Write-Warning "Failed to set Start_TrackProgs: $_"
Add-Content -Path $logFile -Value "Failed to set Start_TrackProgs: $($_)"
}
$svcName = "WSearch"
try {
if (Get-Service -Name $svcName -ErrorAction SilentlyContinue) {
Write-Output "Stopping service $svcName..."
Stop-Service -Name $svcName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Add-Content -Path $logFile -Value "Stopped $svcName"
} else {
Add-Content -Path $logFile -Value "$svcName not found"
}
} catch {
Write-Warning "Could not stop $($svcName): $($_)"
Add-Content -Path $logFile -Value "Could not stop $($svcName): $($_)"
}
$packagesPath = Join-Path $env:LOCALAPPDATA "Packages"
$searchPkgs = Get-ChildItem -Path $packagesPath -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -like "Microsoft.Windows.Search*" }
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupRoot = Join-Path $env:LOCALAPPDATA "DeviceSearchCacheBackup_$timestamp"
New-Item -Path $backupRoot -ItemType Directory -Force | Out-Null
$foundAny = $false
foreach ($pkg in $searchPkgs) {
$cachePath = Join-Path $pkg.FullName "LocalState\DeviceSearchCache"
if (Test-Path $cachePath) {
$foundAny = $true
$dest = Join-Path $backupRoot ($pkg.Name + "_DeviceSearchCache")
try {
Move-Item -Path $cachePath -Destination $dest -Force -ErrorAction Stop
Write-Output "Moved DeviceSearchCache from '$cachePath' to backup '$dest'"
Add-Content -Path $logFile -Value "Moved '$cachePath' -> '$dest'"
} catch {
Write-Warning "Could not move '$cachePath' (will attempt remove): $($_)"
Add-Content -Path $logFile -Value "Move failed for '$cachePath': $($_)"
try {
Remove-Item -Path $cachePath -Recurse -Force -ErrorAction Stop
Write-Output "Removed DeviceSearchCache at '$cachePath'"
Add-Content -Path $logFile -Value "Removed '$cachePath'"
} catch {
Write-Warning "Failed to remove '$cachePath': $($_)"
Add-Content -Path $logFile -Value "Failed to remove '$cachePath': $($_)"
}
}
} else {
Add-Content -Path $logFile -Value "No DeviceSearchCache at expected path: $cachePath"
}
}
if (-not $foundAny) {
Write-Output "No Microsoft.Windows.Search package folder with DeviceSearchCache was found under $packagesPath"
Add-Content -Path $logFile -Value "No DeviceSearchCache found in any Microsoft.Windows.Search package"
}
try {
Start-Service -Name $svcName -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Add-Content -Path $logFile -Value "Started $svcName"
Write-Output "Restarted Windows Search service ($svcName)."
} catch {
Write-Warning "Could not start $($svcName): $($_)"
Add-Content -Path $logFile -Value "Could not start $($svcName): $($_)"
}
try {
Write-Output "Restarting Explorer to refresh Start/search UI..."
Add-Content -Path $logFile -Value "Restarting Explorer..."
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Start-Process explorer.exe
Add-Content -Path $logFile -Value "Explorer restarted."
} catch {
Write-Warning "Failed to restart Explorer: $($_)"
Add-Content -Path $logFile -Value "Failed to restart Explorer: $($_)"
}
Add-Content -Path $logFile -Value "==== Completed run: $(Get-Date -Format u) ===="
Write-Output "Done. Log written to: $logFile"
if ($foundAny) { Write-Output "DeviceSearchCache was backed up to: $backupRoot" } else { Write-Output "No DeviceSearchCache folders were found to back up." }
Write-Output "To undo Start_TrackProgs run: Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced' -Name 'Start_TrackProgs' -Type DWord -Value 1"