locked
PShell Scheduled Task RRS feed

  • Question

  • Would like to defrag Windows Search Index DB on a weekly basis take about 40 min for defrag.

    Temporarily disable the service > stop service > defrag db > enable service  > start service

    Schedule: Powershell.exe -ExecutionPolicy ByPass -File "Path to script"

    Is below script all that is needed, will PShell process next step only after finishing another or do I need to have a pause long enough to finish defrag before starting service??

    Set-Service WSearch –StartupType “Disabled”

    Stop-Service WSearch

    esentutl.exe /d “G:\Microsoft Search Index\Search\Data\Applications\Windows\Windows.edb”

    Set-Service WSearch –StartupType “Automatic”

    Start-Service WSearch

    Friday, June 16, 2017 4:00 PM

Answers

  • Have you even tried the script?  Why wouldn't a command wait? 


    \_(ツ)_/

    • Marked as answer by Andy Diaz Monday, June 19, 2017 2:30 PM
    Friday, June 16, 2017 4:06 PM

All replies

  • Have you even tried the script?  Why wouldn't a command wait? 


    \_(ツ)_/

    • Marked as answer by Andy Diaz Monday, June 19, 2017 2:30 PM
    Friday, June 16, 2017 4:06 PM
  • Nope have not yet tried. Ok got it.

    Will run as is.

    Thanks!

    Friday, June 16, 2017 4:12 PM
  • Try it at a command line first.  Always test scripts before using in scheduler.  Basic computing rule.


    \_(ツ)_/

    Friday, June 16, 2017 4:28 PM
  • ok, thanks!
    Friday, June 16, 2017 4:30 PM
  • Hi,

    >>Is below script all that is needed, will PShell process next step only after finishing another or do I need to have a pause long enough to finish defrag before starting service??

    You could also add a if judgement for instance:

    if(defrag compete)
    
    {
    
      start-service
    
      do other things
    
    }

    Besides, did you have any updates for this thread?

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, June 19, 2017 8:49 AM
  • Tried it manually and it worked.

    Thanks!

    Monday, June 19, 2017 2:29 PM