Powershell – Rebuild Windows Search Index

# Title: Fix Windows Search Index

# Date: 03-Dez-2018
# Author: Matthias Tschopp
# Version: 01

# 1st step – stop Windows Search service

$Statusservice1 = (Get-Service -Name WSearch).Status
If ($Statusservice1 -eq „Running“){
Stop-Service -Name „WSearch“

# 2nd step – remove existing Windows search index file

$EDB = (Test-Path $env:ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb)
If ($EDB -eq „True“){
Remove-Item -Path $env:ProgramData\Microsoft\Search\Data\Applications\Windows\Windows.edb -Force

# 3rd step – restart Windows Search service in order to rebuild the index

Restart-Service -Name „WSearch“

# 4th step – additional check whether the service is really running again

$Statusservice2 = (Get-Service -Name WSearch).Status
If ($Statusservice2 -eq „Stopped“){
Restart-Service -Name „WSearch“