Powershell – Add Scheduled Task to reset search indexes for Exchange 2007

exchange-2007powershell

I simply want to run a ResetSearchIndex -force on a schedule. What is the correct usage for the command in the Scheduled Task properties? It seems I would first need to start Powershell, then load the console file or snap-in for Exchange, which one of these is the closest:

C:\WINDOWS\system32\WINDOW~2\v1.0\POWERS~1.EXE -"D:\Program Files\Microsoft\Exchange Server\Scripts" ResetSearchIndex.ps1 -force dbname

or

C:\WINDOWS\system32\WINDOW~2\v1.0\POWERS~1.EXE -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ".'D:\Program Files\Microsoft\Exchange Server\Scripts' ResetSearchIndex.ps1 -force dbname

or

C:\WINDOWS\system32\WINDOW~2\v1.0\POWERS~1.EXE -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ".'D:\Program Files\Microsoft\Exchange Server\Scripts\ResetSearchIndex.ps1' -force dbname

Best Answer

The third option should do what you want:

C:\WINDOWS\system32\WINDOW~2\v1.0\POWERS~1.EXE -PSConsoleFile "D:\Program 
Files\Microsoft\Exchange Server\bin\exshell.psc1" -noexit -command ".'D:\Program 
Files\Microsoft\Exchange Server\Scripts\ResetSearchIndex.ps1' -force dbname