Search code examples
regexwindowscommand-linetimeoutfindstr

Windows Command to Delay The Output And Then Find a String


I am trying to do the following on Windows Command Line:

gpresult /Scope User /v Gets the results of the current user group policies set, then using a command such as ping or timeout, create a delay and then execute

findstr "ScreenSaveActive"

I have tried to do the following, for example, trying to accomplish the above but have been unsuccessful:

gpresult /Scope User /v | timeout /t 5 /nobreak | findstr "ScreenSaveActive"

Solution

  • This is easier done in Powershell with a command such as:

    gpresult /Scope User /v | out-string -stream | select-string "ScreenSaveActive"
    

    And you could run it from cmd like:

    Powershell -Command "gpresult /Scope User /v | out-string -stream | select-string 'ScreenSaveActive'"