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 ...
    • Troubleshooting SharePoint Links Not Opening in Your Browser

      Introduction: SharePoint is a powerful platform for sharing and collaborating on documents and content. However, sometimes you might encounter an issue where SharePoint links don't open in your browser. Don't worry; we've put together a simple ...
    • How to Safely Move Emails Older than One Year to an Archive

      Keeping your email inbox organized and reducing storage usage is essential, especially for businesses with limited email storage space. Moving emails older than a year to an archive helps improve email performance and keeps your inbox manageable. ...
    • How to Improve Slow Wi-Fi for Remote and Office Employees

      Whether you’re working from home or in the office, slow Wi-Fi can be incredibly frustrating and hinder your productivity. With the rise of hybrid and remote work, having a fast and reliable internet connection is essential for any employee. In this ...
    • How to Troubleshoot and Fix Slow Computer Performance

      A slow computer can be incredibly frustrating and reduce overall productivity, especially for small businesses that rely on fast systems to complete daily tasks. Whether it’s sluggish software, long boot times, or unresponsive programs, performance ...