Update failed: Cumulative Update for Windows 11, version 25H2 for x64-based Systems (KB5070773) (26200.6901)

Morning Distorted Vision — nice work removing Windows.old. Below are a few simple ways to create a System Restore point in Windows 11: the GUI method (recommended), a PowerShell method (quick, scriptable), how to verify it, and short troubleshooting tips.
1) Create a restore point (GUI — easiest)
  1. Click Start, type Create a restore point and press Enter.
    • (Or press Win+R, type sysdm.cpl and press Enter → Advanced tab → System Protection.)
  2. In the System Properties window that opens, click the System Protection tab.
  3. Select the drive you want protection for (usually C and click Configure.
  4. Choose Turn on system protection, set Max Usage (5–10% is common), then click Apply → OK.
  5. Back in the System Protection tab click Create.
  6. Give the restore point a meaningful name (for example: "Before Oct 25 cleanup" or "After removing Windows.old") and click Create.
  7. Wait — Windows will report when the restore point is created successfully.
Expected result: a short progress dialog, then "The restore point was created successfully."
2) Create a restore point (PowerShell — admin)
  • Open PowerShell as Administrator (right‑click Start → Windows Terminal (Admin) or search PowerShell → Run as administrator).
  • Run:
    Checkpoint-Computer -Description "Before cleanup - Oct 25, 2025" -RestorePointType "MODIFY_SETTINGS"
    Notes:
    • Run as admin and System Protection must be enabled for the drive.
    • If Checkpoint-Computer returns an error, read the Troubleshooting section below.
3) Verify restore points (PowerShell)
  • List existing restore points:
    Get-ComputerRestorePoint
    That will show the description, timestamp, and sequence number for each restore point.
4) Restore from a restore point (GUI)
  • Open Create a restore point as above → System Protection tab → click System Restore… → Next → choose the restore point → Next → Finish.
  • The system will restart and apply the restore point. Your installed programs and system settings will return to the snapshot’s state, but your personal files are not touched.
5) Restore from Recovery Environment (if Windows won’t boot)
  • Boot into Windows Recovery Environment (hold Shift while selecting Restart, or boot from recovery media).
  • Troubleshoot → Advanced options → System Restore → pick a restore point and apply.
6) Troubleshooting / things to check
  • If System Protection is grayed-out or you can’t create a restore point:
    • Ensure the drive has System Protection turned on (System Properties → System Protection tab → Configure).
    • Ensure the Volume Shadow Copy and Microsoft Software Shadow Copy Provider services are running:
    • Start them from Services (services.msc) or run as admin:
      Code:
      sc start vss
      sc start swprv
    • Check disk space used by restore points:
      vssadmin list shadowstorage
    • If Checkpoint-Computer fails, the common causes are: System Protection disabled, insufficient disk quota for restore points, or Group Policy blocking restore points.
  • Reminder: System Restore does not back up user documents — it restores system files, the registry and program files. For full safety, consider creating a system image or a File History/backup of your personal data.
7) Good practice
  • Create a restore point just before major changes (driver updates, large Windows updates, major app installs).
  • Give descriptive names and include the date/time.
  • Keep a regular backup (File History, third-party imaging, or full system image) alongside restore points.
If you want, I can:
  • Walk you through the GUI steps with screenshots,
  • Run the PowerShell commands for you (tell me if you want the exact command text copied),
  • Or check whether System Protection is currently enabled on your C: drive (I can give the exact commands to run and how to paste the results here).
Which would you prefer?
 
Adobe Creative Cloud Collection installed.

One final issue to resolve.

How do I disable:

Recent
Quick Searches
Top Apps

From Windows search bar?
 
Morning Distorted Vision — nice setup. Here’s how to remove or reduce the Recent / Quick searches / Top apps items you’re seeing in the Windows 11 search flyout, from easiest (supported Settings) to a couple of more aggressive workarounds.
Quick summary (recommended order)
  • Turn off Search history and Search highlights (Settings). This removes recent searches and the web/content “highlights.”
  • Turn off app‑tracking and “most used”/recent items in Start (Settings) — this removes the Top Apps and Recent items Windows learns from your launches.
  • If you still want no Search flyout content at all, hide the search box/icon on the taskbar (Taskbar settings) and use Win+S / Start typing when you need search.
Step‑by‑step (GUI)
1) Remove Recent (search history)
  • Open Settings → Privacy & security → Search permissions.
  • Under History: turn off “Search history on this device” and click “Clear device search history.”
    This prevents Windows saving new searches and clears what’s stored.
2) Turn off Search Highlights / web content
  • In the same Search permissions page, under More settings, turn off “Show search highlights.”
    This removes the web/content highlights from the search pane. Note: after turning it off you may still see Quick searches and Top apps.
3) Remove Top Apps / Recent apps Windows tracks
  • Settings → Privacy & security → General → turn off “Let Windows improve Start and search results by tracking app launches.”
  • Settings → Personalization → Start → turn off “Show most used apps” and “Show recently opened items in Start, Jump Lists, and File Explorer.”
    Turning off the app‑launch tracking plus those Start settings prevents Windows from populating the Top Apps / recent list.
4) If you still see the small Quick searches / Top apps lists and want them gone completely
  • Easiest non‑destructive option: hide the Search box (right‑click taskbar → Taskbar settings → Taskbar items → Search → set to Hide). You can still search with Win+S or Start then type. This removes the flyout UI from the taskbar.
Advanced / optional (less recommended)
  • Clearing the Search cache (temporary) — Windows stores a DeviceSearchCache that repopulates. Deleting it clears Top Apps temporarily; it will be recreated. Some users create a junction to block it permanently, but that’s a hack and can break search behaviour for some apps. If you want the path and safe removal steps, I can paste the exact commands — note the Package folder name can vary by build. (discussion / workaround example on Microsoft Q&A).
Notes & caveats
  • There’s no single “remove Top apps / quick searches” master switch in current Windows 11 — the supported approach is the Settings toggles above. Some heavy manual hacks exist (DeviceSearchCache deletion/junction or disabling Windows Search) but they have side effects (search breaks, apps not found, or things repopulate).
  • After changing these settings, sign out / restart or open and close Search a couple of times to force the UI to refresh on some builds.
Want me to:
  • Give the exact PowerShell/RegEdit commands to turn off the app‑tracking setting (Start_TrackProgs) and clear DeviceSearchCache?
  • Or walk you through the GUI clicks with screenshots for your exact build?
Tell me which option you prefer and I’ll post the safe commands or show screenshots.
 
I completed steps 1-4. I'm still seeing:

Recent
Quick Searches
Top Apps

in search bar.

Give me the exact PowerShell/RegEdit commands to turn off the app‑tracking setting (Start_TrackProgs) and clear DeviceSearchCache
 
Good — below are exact, copy/paste-ready commands (PowerShell and reg.exe) to 1) set Start_TrackProgs off, 2) clear the DeviceSearchCache safely, and 3) restart the shell/search so the changes take effect. I also include the undo lines and a couple of checks. These steps are the safer, supported-ish approach — deleting DeviceSearchCache only clears the cached “Top apps/Quick searches” temporarily; Windows will rebuild it over time.
Important notes before you run anything
  • Run the PowerShell blocks as Administrator (right‑click Start → Windows Terminal (Admin) or PowerShell (Admin)) except where I call out HKCU edits (those don’t need elevation).
  • I recommend you sign out/sign in or restart Explorer after the registry change so Start updates immediately. You’ll see the cache repopulate later if app tracking is still enabled in other places — these commands address the specific registry + cache you asked about.
1) Check current Start_TrackProgs value (optional)
PowerShell:
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name Start_TrackProgs
Registry (cmd):
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Start_TrackProgs
2) Turn off app‑tracking (Start_TrackProgs = 0)
PowerShell (HKCU; does not require elevation):
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_TrackProgs" -Type DWord -Value 0
Or reg.exe (cmd/regedit style):
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Start_TrackProgs /t REG_DWORD /d 0 /f
To undo (set tracking back on):
PowerShell:
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "Start_TrackProgs" -Type DWord -Value 1
Or:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Start_TrackProgs /t REG_DWORD /d 1 /f
(If the value does not exist, the reg add command will create it.) After changing the registry you can restart Explorer so the Start menu/most-used lists refresh:
Restart Explorer (PowerShell — elevated or normal):
Stop-Process -Name explorer -Force
Start-Process explorer.exe
3) Locate and clear DeviceSearchCache (PowerShell — admin)
This finds the per‑user Microsoft.Windows.Search package folder under %LOCALAPPDATA%\Packages, stops Windows Search, removes the DeviceSearchCache folder, then restarts the search service.
Run as Administrator:

stop search service​

Stop-Service -Name WSearch -Force -ErrorAction SilentlyContinue

find Search package folder (user profile)​

$pkg = Get-ChildItem -Path $env:LOCALAPPDATA\Packages | Where-Object { $_.Name -like "Microsoft.Windows.Search*" } | Select-Object -First 1
if ($pkg) {
$cache = Join-Path $pkg.FullName "LocalState\DeviceSearchCache"
if (Test-Path $cache) {
Remove-Item -Path $cache -Recurse -Force -ErrorAction SilentlyContinue
Write-Output "Deleted DeviceSearchCache: $cache"
} else {
Write-Output "No DeviceSearchCache found at: $cache"
}
} else {
Write-Output "Microsoft.Windows.Search package folder not found under $env:LOCALAPPDATA\Packages"
}

restart search service​

Start-Service -Name WSearch -ErrorAction SilentlyContinue
What that does and caveats
  • Stopping WSearch (the Windows Search service) is the safe way to make sure files are not locked when deleting the cache. If Stop-Service fails (permission / service state), you can reboot and run the Remove-Item part early in the session.
  • Deleting DeviceSearchCache clears the flyout’s cached Top Apps / Quick searches temporarily; Windows will repopulate it as you use apps unless tracking is fully disabled (we set Start_TrackProgs = 0 above and you already turned off the Settings toggles).
Alternative: one‑liner PowerShell to delete any DeviceSearchCache found (admin)
Stop-Service WSearch -Force
Get-ChildItem "$env:LOCALAPPDATA\Packages" -Directory | Where-Object Name -Like "Microsoft.Windows.Search*" | ForEach-Object {
$path = Join-Path $_.FullName "LocalState\DeviceSearchCache"
if (Test-Path $path) { Remove-Item -Path $path -Recurse -Force -ErrorAction SilentlyContinue; Write-Output "Removed $path" }
}
Start-Service WSearch
4) Force Search UI refresh
  • After clearing cache and changing the reg value, sign out/in or restart Explorer (see Restart Explorer above). Also open the search flyout a few times to let Windows rebuild any cached lists. A reboot will certainly apply everything.
5) Extra checks
  • Confirm Start_TrackProgs is 0:
    reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v Start_TrackProgs
  • List remaining DeviceSearchCache (if any):
    Get-ChildItem "$env:LOCALAPPDATA\Packages\Microsoft.Windows.Search*" -Recurse -Directory | Where-Object Name -eq "DeviceSearchCache"
Why you still might see items
  • Even after the above, Windows can repopulate suggestions from other signals (cloud / web suggestions or other telemetry settings). You already turned off the Settings toggles, which is the main supported method — clearing DeviceSearchCache just removes the local cache immediately. See earlier notes about Settings toggles + cache behavior.
If you want, I can:
  • Paste the exact commands into a single runnable PowerShell script for you to run as Admin, or
  • Walk you through running these one step at a time in your session and confirm the results.
Which do you prefer?
 
Good — below is a ready-to-run PowerShell script you can save as Clear-SearchCacheAndDisableTracking.ps1 and run as Administrator. It:
  • disables Start_TrackProgs (turns off app‑launch tracking),
  • stops Windows Search, finds and moves (backs up) any DeviceSearchCache for your user,
  • restarts Windows Search and Explorer so the UI refreshes,
  • logs actions and records the previous Start_TrackProgs value so you can undo.
This is the safer approach (it backs up the cache instead of permanently deleting it). It follows the steps we discussed earlier.
PowerShell script (save exactly, then run in an elevated PowerShell)
Code:
<#
.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."
How to use (quick)
  1. Save the script file to your downloads or Documents folder as Clear-SearchCacheAndDisableTracking.ps1.
  2. Open Start → Windows Terminal (Admin) or PowerShell (Admin).
  3. Navigate to the script folder, then run:
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
    .\Clear-SearchCacheAndDisableTracking.ps1
  4. After the script finishes, sign out/sign in or reboot if anything still appears.
If you want I can:
  • produce a single one-line command to paste into an already-elevated shell instead of saving a file; or
  • modify the script to permanently delete (no backup) the cache instead of moving it; or
  • add an -Undo parameter that restores Start_TrackProgs and (optionally) moves backup cache back.
Which would you like?
 
Thanks — that error is the cause and it’s easy to fix.
Why it happened
  • PowerShell complains because the string contained $svcName: $_ — the colon after the variable name makes the parser try to treat "$svcName:" as a variable/drive token. PowerShell wants the variable name delimited when followed by punctuation. Use $() (or $() around each variable) or string formatting so the parser knows where the variable name ends. (This is why the error message suggested using ${} to delimit the name.)
Quick fix
  • Replace every instance of "… $svcName: $" (and "… $svcName: $" in Add-Content lines) with either:
    • "$($svcName): $($_)" (easy, readable)
    • or use the formatting operator: "Could not stop {0}: {1}" -f $svcName, $_
Corrected script
Save this as Clear-SearchCacheAndDisableTracking.ps1 (replace your current file), then run from an elevated PowerShell:
Code:
# (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"
How to run
  1. Save the corrected file.
  2. Open Windows Terminal (Admin) or PowerShell (Admin).
  3. cd to the folder and run:
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
    .\Clear-SearchCacheAndDisableTracking.ps1
If you prefer I can:
  • upload the corrected script text as a file for you to download, or
  • paste a single one-line command to patch the current script file in-place.
Extra note: we discussed why clearing the cache is temporary and that Windows may rebuild Top Apps unless tracking is disabled in Settings — that guidance is in my earlier post.
Which do you want next — I can (A) paste the one-liner to fix your current .ps1 in-place, or (B) upload the corrected .ps1 for you to download, or (C) have you run the corrected file now and report the log output (I’ll tell you what to paste)?
 
Thanks — that error is clear and easy to fix.
Cause
  • Your PowerShell session is the built‑in Windows PowerShell (5.1). My script used a C‑style ternary expression ( ? : ) inside a string to produce a short value — that syntax is only supported in PowerShell 7+. PowerShell 5.1 throws "Unexpected token '?'" when it sees that.
Quick fix (edit just two lines)
  1. Open the script in Notepad (from an elevated PowerShell / terminal you were already using):
    notepad .\Clear-SearchCacheAndDisableTracking.ps1
  2. Find this line (the one that caused the error):
    Add-Content -Path $logFile -Value "Previous Start_TrackProgs value: $($oldVal -ne $null ? $oldVal.ToString() : '<not present>')"
  3. Replace it with these two lines:
    $oldValString = if ($null -ne $oldVal) { $oldVal.ToString() } else { '<not present>' }
    Add-Content -Path $logFile -Value "Previous Start_TrackProgs value: $oldValString"
  4. Save the file and rerun the script (still in an elevated shell):
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
    .\Clear-SearchCacheAndDisableTracking.ps1
Why this works
  • The replacement uses PowerShell 5.1 compatible if/else to build a safe string, then writes that string to the log. No ternary operator needed.
If you prefer I can:
  • paste the entire corrected script here for you to overwrite your file, or
  • patch the script for you with a single command (I can give the one‑liner to run in elevated PowerShell that makes the exact replacement), or
  • skip the script and run the three commands manually now to disable Start_TrackProgs and remove the cache — tell me which.
Which do you want me to do?
 
Short answer: Yes — it makes sense to upgrade to PowerShell 7 for modern features (ternary ?:, pipeline-chain operators, faster startup in many cases, cross‑platform improvements, long‑term .NET support). It installs side‑by‑side with Windows PowerShell 5.1, won’t remove the built‑in version, and you can keep using 5.1 when scripts or modules require it.
Below is a concise, practical guide: why, risks/caveats, and three safe installation options (recommended order) plus how to run your script in pwsh once installed.
Why upgrade
  • New language features (ternary operator, pipeline chaining, null coalescing, etc.) so scripts written for PS7 won’t error in 5.1.
  • Actively maintained on modern .NET (better performance and security updates).
  • Can be set as your interactive default (Windows Terminal, VS Code) while keeping system PowerShell for OS tasks.
Main caveats
  • PowerShell 7 (pwsh.exe) is side‑by‑side — it does not replace Windows PowerShell (powershell.exe). Some Windows modules that depend on the full .NET Framework may not work in PS7. If a module fails, run it in Windows PowerShell 5.1 or use compatibility tools.
  • If you have scripts that rely on 5.1 behavior, test them before switching defaults.
  • Installing from Microsoft Store auto‑updates; MSI / winget give you manual control.
How to install (3 safe options)
Option A — Microsoft Store (recommended for easiest updates)
  1. Open Microsoft Store.
  2. Search for “PowerShell” (publisher: Microsoft Corporation).
  3. Install the app. It will add pwsh to your Start menu and auto‑update via Store.
Option B — Official MSI (download from GitHub releases)
  1. Open the official PowerShell releases page (PowerShell/PowerShell on GitHub) and download the latest stable Windows MSI for your architecture (x64 or x86).
  2. Run the MSI as Administrator and follow the installer. By default it adds pwsh.exe to your PATH.
  3. After installation you can launch PowerShell 7 as “PowerShell” or “pwsh” from Start/Terminal.
Option C — winget (command line)
  1. In an elevated or normal command prompt, run:
    • winget search PowerShell
    • note the package Id shown (it will be something like a PowerShell package by Microsoft)
    • then run: winget install <PackageId> --exact
      If you want, I can look up the exact current winget Id for you and paste the single command to run.
After install — run your script under pwsh
  • Open PowerShell 7 from Start (or run pwsh from terminal) and run:
    pwsh -NoProfile -ExecutionPolicy Bypass -File .\Clear-SearchCacheAndDisableTracking.ps1
    This runs the script using PowerShell 7 and will avoid the 5.1 parsing errors you saw.
Make PowerShell 7 your default shell in Windows Terminal (optional)
  • Open Windows Terminal → Settings → Default profile → choose the PowerShell 7 profile (usually named “PowerShell” or “pwsh”). This only affects interactive sessions launched from Terminal.
Compatibility help
  • If a module isn’t working in PS7, you can:
    • Run it in Windows PowerShell (powershell.exe) for that task, or
    • Use the WindowsCompatibility/WindowsCompatibilityHelper approach (there’s a community/official compatibility helper to auto‑import modules into PS7 via implicit remoting) — I can provide commands if you hit a broken module.
Uninstall / revert
  • Uninstall via Settings → Apps → Installed apps (find “PowerShell” and uninstall) or use Programs & Features if installed via MSI. Microsoft Store apps can be removed from the Store UI.
Recommendation for your situation
  • Yes — install PowerShell 7 (Microsoft Store or MSI). Then run the corrected script in pwsh (just use the pwsh command above). That will let you use the ternary/other new operators without changing the script for PS5.1.
Would you like:
A) a single copy/paste winget command I can give you (I’ll confirm the exact package Id first), or
B) a direct MSI download instruction with the exact filename you should grab (I can paste the exact filename to look for on GitHub), or
C) the exact one‑line command to run your script under pwsh right now if you already installed PS7?
Tell me which and I’ll paste the exact command.
 
Thanks — that screenshot shows the issue: you tried to pass the version number to winget (winget install 7.5.4.0) which won’t work. winget needs the package Id (or the package name as shown by winget search). Here are the correct steps and exact commands.
1) Search for the package Id (optional — confirms what winget sees)
  • Open an elevated Command Prompt / PowerShell (recommended for installs) and run:
    winget search --source winget PowerShell
2) Install the stable PowerShell 7 (correct command)
  • Run as Administrator:
    winget install --id Microsoft.PowerShell --exact
    (short form: winget install --id Microsoft.PowerShell -e)
3) If you want the preview build instead:
winget install --id Microsoft.PowerShell.Preview --exact
4) Verify the install
  • After installation, confirm version:
    pwsh --version
5) Run your script under PowerShell 7
  • From the same elevated prompt (or a new pwsh session):
    pwsh -NoProfile -ExecutionPolicy Bypass -File "C:\path\Clear-SearchCacheAndDisableTracking.ps1"
    (use the actual path where you saved the script)
If winget still reports “No package found matching input criteria”:
  • Run: winget show --id Microsoft.PowerShell
    That will show if the package exists in your winget source. If the Id differs on your machine, use the Id shown by winget show or winget search.
Alternatives
  • Microsoft Store: install “PowerShell” (store entry) — convenient because the Store auto‑updates.
  • MSI from GitHub releases: download and run the official MSI if you prefer manual control.
Would you like me to:
  • paste a single copy/paste command to install PowerShell 7 for you now, or
  • walk you through the install interactively and then run the script under pwsh and show the log output?
Say which and I’ll post the exact single command to run.
 
Thanks — that helps. Because you already disabled Start_TrackProgs and cleared DeviceSearchCache, the remaining items are coming from other signals Windows uses (local usage history stored by Explorer / UserAssist, the search index, and cloud/web suggestion settings). We can remove those too — below I’ll give a safe, reversible plan and the exact commands to run (PowerShell + reg.exe). Read the short summary and the warnings, then tell me if you want me to give you a single script to run or run the steps one-by-one.
Plan (what we’ll do)
1) Backup your Explorer usage data (UserAssist) — reversible.
2) Clear UserAssist “Count” entries (this will remove “most used” activity that fuels Top Apps).
3) Ensure web/cloud suggestions are disabled via registry (Bing/web results).
4) Force Windows Search to rebuild its index (so Quick Searches / cached results are cleared).
5) Restart Search/Explorer and reboot if you want a full refresh.
Important warnings
  • Clearing UserAssist removes your recorded “most used” counts (Top Apps). It’s reversible only by restoring the backup export file I show.
  • Rebuilding the search index can take some time and will temporarily make Windows Search slower until the index is rebuilt.
  • I’ll include undo steps for everything.
If that’s OK, run these commands (or I can package them into one runnable PS script). Run in an elevated PowerShell (Run as Administrator).
Step 0 — quick check (optional)
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name Start_TrackProgs
Step 1 — Backup UserAssist (safe, saves to Desktop)
(reg export creates a .reg file you can re-import to restore)
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist" "%USERPROFILE%\Desktop\UserAssistBackup.reg" /y
Step 2 — Clear UserAssist “Count” entries (removes most-used/app launch counts)
PowerShell (elevated):
$ua = Get-ChildItem -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist' -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -eq 'Count' }
foreach ($k in $ua) {
Remove-Item -Path $k.PSPath -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Output "UserAssist Count keys removed. Backup is on Desktop as UserAssistBackup.reg"
Undo: to restore (if you change your mind)
reg import "%USERPROFILE%\Desktop\UserAssistBackup.reg"
Step 3 — Disable web/cloud suggestions in the Search registry (makes search local-only)
(reg key changes are per-user; these are safe and reversible)
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v BingSearchEnabled /t REG_DWORD /d 0 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v CortanaConsent /t REG_DWORD /d 0 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v AllowSearchToUseLocation /t REG_DWORD /d 0 /f
Also double-check in Settings (you probably did this already):
Settings → Privacy & security → Search permissions → under History click Clear device search history; under More settings turn off Show search highlights and turn off “Search online and include web results” if present.
Undo: set the values back to 1
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v BingSearchEnabled /t REG_DWORD /d 1 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v CortanaConsent /t REG_DWORD /d 1 /f
Step 4 — Force a Search index rebuild (clears index and forces repopulation)
Option A — GUI (safe):
  • Control Panel → Indexing Options → Advanced → Rebuild (this is simple and recommended).
Option B — aggressive (PowerShell; deletes index files then restarts Windows Search)
Run elevated PowerShell:
Stop-Service -Name WSearch -Force -ErrorAction SilentlyContinue

rename the index folder (keeps a copy)​

$idx = "$envrogramData\Microsoft\Search\Data\Applications\Windows"
$backup = "$envrogramData\Microsoft\Search\Data\Applications\Windowsbackup$(Get-Date -Format yyyyMMdd_HHmmss)"
if (Test-Path $idx) { Rename-Item -Path $idx -NewName $backup -Force -ErrorAction SilentlyContinue }
Start-Service -Name WSearch -ErrorAction SilentlyContinue
Write-Output "Index folder was renamed to: $backup. Windows Search will recreate the index (may take a while)."
Undo: You can remove the backup folder if everything is fine, or restore it by stopping WSearch and renaming back (but normally Windows will rebuild a fresh index).
Step 5 — Restart Explorer and optionally reboot

restart explorer (will close/start shell)​

Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
Start-Process explorer.exe
Recommendation: after Steps 1–4, sign out and sign in or reboot once to ensure Start/search UI refreshes fully.
Why you might still see items even after these steps
  • Some entries (Quick searches / Recent) can be repopulated from cloud/online signals or from the rebuilt index as apps are used. The combination above removes the local signals (UserAssist counts, index, device search history) and disables web suggestions so new entries should be minimal going forward.
Want me to:
A) Provide a single PowerShell script that does all of the above (with prompts and backups) and prints a short summary at the end; or
B) Have you run the commands above step-by-step and paste the output if anything errors; or
C) I can walk you through the GUI Indexing rebuild + quick registry checks only (less invasive)?
Choose A, B or C and I’ll supply the exact script or the next command to run.
 
Thanks — that error message explains what happened. PowerShell didn’t expand %USERPROFILE% the way CMD would, so reg.exe tried to write to a literal path containing %USERPROFILE% and failed. Below are safe, copy/paste commands (with alternatives) to back up UserAssist, clear the Count keys, verify the search registry flags, force an index rebuild, and refresh Explorer/Search. I also include undo steps.
Quick note: you already have Start_TrackProgs = 0, so we’re now removing the remaining local signals (UserAssist counts + search index + cloud flags) that feed Recent / Quick Searches / Top Apps. See earlier notes about how Windows can re‑populate lists over time.
Step A — Back up UserAssist (use this exact command in elevated PowerShell)
This creates a .reg backup on your Desktop (PowerShell expands $env:USERPROFILE correctly).
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist" "$env:USERPROFILE\Desktop\UserAssistBackup.reg" /y
If you prefer a PowerShell-native backup (XML):
$uaKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist'
Get-ChildItem -Path $uaKey -Recurse | Export-Clixml -Path "$env:USERPROFILE\Desktop\UserAssistBackup.xml"
If the reg export still errors, tell me the exact error text — we’ll adjust the path or use the XML backup.
Step B — Clear UserAssist "Count" entries (removes "most used" app counts)
Run in elevated PowerShell:
$ua = Get-ChildItem -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist' -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.PSChildName -eq 'Count' }
foreach ($k in $ua) {
Remove-Item -Path $k.PSPath -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Output "UserAssist Count keys removed. Backup is on Desktop."
Undo: to restore your previous counts (if you used reg export):
reg import "$env:USERPROFILE\Desktop\UserAssistBackup.reg"
Step C — Verify / disable cloud/web search flags (per‑user)
Check current values (run in PowerShell):
Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" -Name BingSearchEnabled,CortanaConsent,AllowSearchToUseLocation -ErrorAction SilentlyContinue
Set them to off (so search is local-only):
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v BingSearchEnabled /t REG_DWORD /d 0 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v CortanaConsent /t REG_DWORD /d 0 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v AllowSearchToUseLocation /t REG_DWORD /d 0 /f
Undo (set back to 1):
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v BingSearchEnabled /t REG_DWORD /d 1 /f
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Search" /v CortanaConsent /t REG_DWORD /d 1 /f
Also double-check in Settings → Privacy & security → Search permissions:
  • turn off Search history on this device (and click Clear device search history)
  • turn off Show search highlights
  • turn off “Search online and include web results” (if present)
Step D — Rebuild/clear the Windows Search index (recommended)
GUI (recommended — safe):
  • Control Panel → Indexing Options → Advanced → Rebuild
PowerShell (aggressive — renames current index so Windows creates a new one):
Stop-Service -Name WSearch -Force -ErrorAction SilentlyContinue
$idx = "$envrogramData\Microsoft\Search\Data\Applications\Windows"
$backup = "$envrogramData\Microsoft\Search\Data\Applications\Windowsbackup$(Get-Date -Format yyyyMMdd_HHmmss)"
if (Test-Path $idx) { Rename-Item -Path $idx -NewName (Split-Path $backup -Leaf) -Force -ErrorAction SilentlyContinue }
Start-Service -Name WSearch -ErrorAction SilentlyContinue
Write-Output "Index folder renamed to $backup (Windows Search will recreate index — may take time)."
Notes:
  • GUI rebuild is easiest and less invasive. The PowerShell rename keeps a backup of the old index if you want to revert.
  • Rebuilding the index can take some minutes and may temporarily make search slower.
Step E — Restart Explorer & sign out / reboot
Restart Explorer to refresh the Start/search UI:
Stop-Process -Name explorer -Force -ErrorAction SilentlyContinue
Start-Process explorer.exe
For a fuller refresh, sign out and sign back in or reboot the PC.
What to expect
  • After clearing UserAssist and rebuilding the index, Top Apps / Most used should be cleared. Quick Searches and Recent should also be reduced once the index is rebuilt and device search history is cleared. If you still see items after reboot, they’re likely coming from cloud/web suggestions or repopulation from app usage — the registry flags above should have stopped cloud suggestions; app usage will repopulate as you launch apps.
If you want, I can:
  • package Steps A–E into a single test-and-execute PowerShell script (with prompts and a dry‑run mode), or
  • walk you through the GUI Indexing Options rebuild and then run just the UserAssist clear for you.
Which do you want me to do next — produce the script, or run Step A (reg export) for you and you paste the result/error?