Resolving Network Search Issues Using PowerShell Script

Resolving Network Search Issues Using PowerShell Script

Issue:

Users may experience an issue where searching for file names longer than four characters on a network results in indefinite loading. This issue is not observed on other PCs within the same network.

Solution:

To resolve this issue, follow these steps to run a PowerShell script that resets the Windows search components and clears related caches. This process requires running the script with administrative privileges and setting the execution policy.

Steps:

  1. Set the PowerShell Execution Policy: Before running the script, you need to set the execution policy to allow the script to run. Open PowerShell as an administrator and execute the following command:

    powershell

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
  2. PowerShell Script to Resolve Network Search Issue: Use the following PowerShell script. Save the script as a .ps1 file, for example, Reset-Search.ps1.

    powershell

    # Function Definitions function T-R { [CmdletBinding()] Param( [String] $n ) $o = Get-Item -LiteralPath $n -ErrorAction SilentlyContinue return ($o -ne $null) } function R-R { [CmdletBinding()] Param( [String] $l ) $m = T-R $l if ($m) { Remove-Item -Path $l -Recurse -ErrorAction SilentlyContinue } } function S-D { R-R "HKLM:\SOFTWARE\Microsoft\Cortana\Testability" R-R "HKLM:\SOFTWARE\Microsoft\Search\Testability" } function K-P { [CmdletBinding()] Param( [String] $g ) $h = Get-Process $g -ErrorAction SilentlyContinue $i = $(get-date).AddSeconds(2) $k = $(get-date) while ((($i - $k) -gt 0) -and $h) { $k = $(get-date) $h = Get-Process $g -ErrorAction SilentlyContinue if ($h) { $h.CloseMainWindow() | Out-Null Stop-Process -Id $h.Id -Force } $h = Get-Process $g -ErrorAction SilentlyContinue } } function D-FF { [CmdletBinding()] Param( [string[]] $e ) foreach ($f in $e) { if (Test-Path -Path $f) { Remove-Item -Recurse -Force $f -ErrorAction SilentlyContinue } } } function D-W { $d = @("$Env:localappdata\Packages\Microsoft.Cortana_8wekyb3d8bbwe\AC\AppCache", "$Env:localappdata\Packages\Microsoft.Cortana_8wekyb3d8bbwe\AC\INetCache", "$Env:localappdata\Packages\Microsoft.Cortana_8wekyb3d8bbwe\AC\INetCookies", "$Env:localappdata\Packages\Microsoft.Cortana_8wekyb3d8bbwe\AC\INetHistory", "$Env:localappdata\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\AC\AppCache", "$Env:localappdata\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\AC\INetCache", "$Env:localappdata\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\AC\INetCookies", "$Env:localappdata\Packages\Microsoft.Windows.Cortana_cw5n1h2txyewy\AC\INetHistory", "$Env:localappdata\Packages\Microsoft.Search_8wekyb3d8bbwe\AC\AppCache", "$Env:localappdata\Packages\Microsoft.Search_8wekyb3d8bbwe\AC\INetCache", "$Env:localappdata\Packages\Microsoft.Search_8wekyb3d8bbwe\AC\INetCookies", "$Env:localappdata\Packages\Microsoft.Search_8wekyb3d8bbwe\AC\INetHistory", "$Env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy\AC\AppCache", "$Env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy\AC\INetCache", "$Env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy\AC\INetCookies", "$Env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy\AC\INetHistory") D-FF $d } function R-L { [CmdletBinding()] Param( [String] $c ) K-P $c 2>&1 | out-null D-W # 2>&1 | out-null K-P $c 2>&1 | out-null Start-Sleep -s 5 } function D-E { Write-Host "Press Enter to continue..." [void][System.Console]::ReadLine() } Write-Output "Verifying that the script is running elevated" if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) { $Cx = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-noexit",$Cx Exit } } $a = "searchui" $b = "$Env:localappdata\Packages\Microsoft.Windows.Search_cw5n1h2txyewy" if (Test-Path -Path $b) { $a = "searchapp" } Write-Output "Resetting Windows Search Box" S-D 2>&1 | out-null R-L $a Write-Output "Done..." D-E
  3. Run the PowerShell Script:

    • Right-click on the saved .ps1 file and select "Run with PowerShell."
    • If prompted, confirm the execution policy change.
    • Follow any on-screen instructions provided by the script.
  4. Monitor the Results:

    • After running the script, test the network search functionality to ensure the issue is resolved.

Additional Tips:

  • Ensure you run the script with administrative privileges.
  • If the issue persists, consider running the script in Safe Mode with Networking to eliminate potential third-party software conflicts.

By following these steps, you should be able to resolve the network search issue on the affected PC. If you encounter any further issues or need assistance, please contact the IT support team.


    • Related Articles

    • How to Troubleshoot Common Windows Server Issues

      Windows Server is a powerful platform for businesses, but like any system, it can encounter issues that disrupt operations. Understanding how to troubleshoot these common problems can save time and keep your system running smoothly. This article ...
    • Managing Printer Issues When Working from Home

      Introduction Printing from home might seem like a simple task, but for many remote workers across the UAE, it becomes a frustrating experience. Whether it is a home printer that refuses to connect to a company laptop, a driver compatibility issue on ...
    • Resolving Shared Folder Access Error (0x800704B) – “Security Policies Block Unauthenticated Guest Access”

      Overview When attempting to access certain shared folders in a Windows environment, you may encounter an error message stating: You can’t access this shared folder because your organization’s security policies block unauthenticated guest access. ...
    • Why Is My VPN Slow? Troubleshooting Remote Access Issues

      Introduction A slow VPN is one of the most frustrating IT problems facing remote workers in the UAE. When employees complain that their VPN-connected systems are sluggish, files take too long to open, or video calls are choppy, productivity suffers — ...
    • How to Fix Audio and Video Issues in Microsoft Teams and Zoom

      Introduction For businesses across the UAE, video conferencing has become the backbone of daily operations — from client meetings to internal team coordination. Microsoft Teams and Zoom are the two most widely used platforms, and when audio or video ...