Logparser error when used with PowerShell

非 Y 不嫁゛ 提交于 2019-12-20 07:27:23

问题


I'm trying to use Log Parser within PowerShell to export a Windows Evtx log file to CSV:

$logparser = "c:\program files (x86)\Log Parser 2.2\logparser.exe"
$allArgs = ("SELECT * INTO c:\logs\logs.csv FROM c:\logs\logs.evtx", "-i:evt", "-o:csv")
$ps = Start-Process -FilePath $logparser -ArguementList $allArgs -Wait -Passthru -NoNewWindow;
$ps.WaitForExit()
$ps.ExitCode;

But when I run this I get an error:

Error: detected extra argument "*" after query

The error code is 13. I tried putting the paths in single quotes and running it from the same directory as the logs but it keeps returning the same error.


回答1:


You need to preserve the double quotes around the query string, otherwise it won't be recognized as a single argument by the spawned process.

Putting the query string (with double quotes) in single quotes might work:

$allArgs = '"SELECT * INTO c:\logs\logs.csv FROM c:\logs\logs.evtx"',
           "-i:evt",
           "-o:csv"

However, a much simpler solution to the problem would be to avoid Start-Process entirely and use the call operator (&) instead:

$logparser = "c:\program files (x86)\Log Parser 2.2\logparser.exe"
$query = "SELECT * INTO c:\logs\logs.csv FROM c:\logs\logs.evtx"

& $logparser -i:evt -o:csv $query


来源:https://stackoverflow.com/questions/37808952/logparser-error-when-used-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!