Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Select-String over multiple lines

$
0
0

Hello,

I am trying to run an IF statement against a string match from a file. from the file. i am looking to find a match on this:

State           : Failed
Severity        : Error

I firstly load a variable like this

$stringmatch = Get-Content "c:\test.txt"

my if statement looks like this but gives me an error

if(Select-String "State           : Failed`nSeverity        : Error" $stringmatch)

{

}

I thought if i used the `n this would designate a new line in my string, the error i get when i run it is

Select-String : Cannot bind argument to parameter 'Path' because it is an empty string.

+ if(Select-String "State           : Failed`nSeverity        : Error" $stringmatch)
+                                                                      ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Select-String], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.SelectStringCommand

the $stringmatch variable does contain strings I have checked.

thanks

Steve


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>