powershell - An empty pipe element is not allowed, Get-WinEvent -FilterHashtable -
i'm new powershell (v5) found on web way list non empty logs e.g. in last 30 minutes. however, cannot redirect output file. suggestions gratefully received.
$time1 = new-timespan -minutes 30 $logs = get-winevent -listlog * | where-object {$_.recordcount} | select-object -expandproperty logname get-winevent -filterhashtable @{logname=$logs; level=1,2,3; starttime=(get-date)-$time1} | out-file c:\temp\test1.txt
there 2 ways make powershell continuation of pipeline on next line:
place
|@ end of line.- more generally: statement invariably needs more tokens syntactically valid causes powershell keep parsing on next line.
use explicit line continuation placing
`(powershell's escape character) @ very end of line (not whitespace allowed after).- note: unlike posix-like shells
\, powershell retains newline follows`. between arguments difference doesn't matter, if use`<newline>in middle of argument, newline becomes part of argument.
- note: unlike posix-like shells
what tried:
powershell reads following two statements:
get-winevent -filterhashtable @{logname=$logs; level=1,2,3; starttime=(get-date)-$time1} | out-file c:\temp\test1.txt the get-winevent line syntactically complete itself, powershell considers own statement.
thus, powershell, next statement starts with |, prompts error message saw (there must command or expression before statement's first |).
that said, changing powershell's parsing | first (non-whitespace) character on next line has been suggested.
Comments
Post a Comment