I'm trying to call a powershell script from a batch file.
I have the following
for /F "usebackq delims=" %%a in (
'PowerShell.exe -ExecutionPolicy ByPass -Command "(@(Select-String %QUERY% %FILE% -Context 0, 1 | % {$_.Context.PostContext} ))"'
) do set RESULT=%%a
echo %RESULT%
But the %RESULT%
is printing the whole command not the result.
All I'm trying to do is read a file for a flag and then return the next line as the %RESULT%
I ran the following from command line
PowerShell.exe -ExecutionPolicy ByPass -Command "& (Select-String FAILED e:\path\to\app.log -Context 0, 1 | % {$_.Context.PostContext} )"
and got this
& : The term ':generic/generic.k4.csv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & (Select-String FAILED e:\path\to\app.log -Context 0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:generic/generic.k4.csv:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException