PowerShell 및 Logparser 인수
-
05-07-2019 - |
문제
나는 PowerShell에서 일부 로그 패러 명령을 실행하려고하지만 인수를 올바르게 전달하는 데 문제가 있는데, 그녀는 내 스크립트의 Excert입니다.
D : 스크립팅 smtplogs logparser logparser.exe "상위 50 개 수신기 선택, count () inton tmpoutput% topreceiversndrall.gif in%tempdir% postall.log에서 발신자가 '<>'을 좋아하지 않는 '%% go-fmtopper %%'그룹에 의한 수신기 주문 (count).) desc "-i : tsv -iseparator : space -HeaderRow : OFF -IheaderFile :"header3.tsv " -라인 필터 :"+10. "-o : Chart -ChartType : ColumnClustered -config : myscript.js -charttitle :"수신기 : "수신기 :"수신기 " 널 메시지의 경우 모든 %dategraph %"
나는 논쟁을 캡슐화하는 것에 대한로드를 읽었지만이 작업을 수행하는 방법을 알아낼 수없는 것 같습니다!
여러분이 제공 할 수있는 도움은 대단히 감사 할 것입니다.
감사
해결책
For a complex string parameter, try to pass the argument using powershell here-strings so that you wouldn't have to worry about escaping single/double quotes
UPDATE1: I couldn't get the fomratting working so here is the screenshot.
UPDATE2: I was able to format the code finally.
d:\scripting\smtplogs\logparser\logparser.exe @" SELECT TOP 50 Receiver, COUNT() INTO %TMPOutput%\TopReceiversNDRALL.gif FROM %TempDir%\PostAll.log WHERE Sender LIKE '' AND Receiver NOT LIKE '%%go-fmtopper%%' GROUP BY Receiver ORDER BY COUNT() DESC" -i:TSV -iSeparator:space -headerRow:OFF -iHeaderFile:"header3.tsv" -lineFilter:"+10." -o:CHART -chartType:ColumnClustered -config:MyScript.js -chartTitle:"Receivers for NULL messages ALL for %DateGraph% "@
Make sure that you add a new line between the here-string monikers @" and "@.
다른 팁
FYI, if you don't need any PowerShell variable expansion then you are better off using single quoted here strings. For example the following double quoted here string might cause you some grief:
@"
$(get-process <some_core_os_process> | stop-process)
"@
where the following is harmless:
@'
$(get-process <some_core_os_process> | stop-process)
'@
It's not likely your here string would contain something so obvious but a simple $f would resolve to nothing i.e. it would disappear from the original string. Unless, of course, $f was defined and set to something other than null or empty.