
By contrast, Get-Date | Select-String January is the equivalent of. Get-Date | Out-String -Stream | findstr January Get-Date | findstr January works (in en-based cultures), because it is implicitly the same as. You shouldn't have to do this manually, however: Select-String should do it implicitly, as suggested in GitHub issue #10726.Ĭuriously, when piping to external programs such as findstr.exe, PowerShell already does apply Out-String -Stream implicitly e.g:. In order to find strings among the lines of the for-display string representations of non-string input objects as they would print to the console you indeed have to pipe to Out-String -Stream, whereas by default, simple. To complement AdminOfThings' helpful answer: In particular, Get-Service | Out-String | sls "Sec" does return stuff, just not the stuff I was expecting (is it searching for each character of "s" and "e" and "c" so is returning lots - that would not be very intuitive if so in my opinion)? Would appreciate if someone could clarify how things fit together in the above so that I can make more use of sls. How in general should I turn an object into a string so that it can manipulate the information (in the same way that Get-Service | findstr "Sec" can do so easily)? (Get-Service).ToString() | sls "Sec" (.ToString() just returns "System.Object") Get-Service | Out-String | sls "Sec" (gives results, but odd)
So, my thinking is "ok, I need to make the output from Get-Service into a string to work with PowerShell Cmdlets", but that doesn't work (or not in a way that I would expect): Sls examples: sls "search text" *.log cat *.log | grep "search text"Īs an aside, all PowerShell Cmdlets are case-insensitive, unlike Linux tools which are generally always case-sensitive but also older tools like findstr which are case sensitive too, but findstr can be used in PowerShell, and works in situations where sls does not, for example: Get-Service | findstr "Sec" (this works without a problem!), but when we try to use sls in a similar way Get-Service | sls "Sec" we get nothing (presumably this fails because sls works with strings, but Get-Service returns an object, so that's understandable - but what is findstr doing then in that it can see the output as a string?).
Grep examples: grep "search text" *.log cat *.log | grep "search text" (default parameter position for sls is pattern then file) Could someone clarify how sls (Select-String) works compared to grep and findstr?