Powershell and logparser arguments
Asked Answered
H

2

7

Im trying to run some logparser commands from powershell but Im having issues with passing the arguments across correctly, heres the excert from my script;

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%"

Ive read loads about encapsulating arguments but cant seem to figure out how to make this work!

Any help that you guys could provide would be very appreciated.

Thanks

Helenehelenka answered 9/3, 2009 at 5:2 Comment(3)
+1 - Not sure why this got voted down, seems like a fine question to me... Fellow Andy looking out for other AndysFreshman
Yeah it puzzled me, I know its abit of a noob question but its annoying the life out of me!Helenehelenka
+1 Yeah, I consider this a valid question since it's sometimes quite perplexing how to pass a string with a lot of single/double quotes in it.Yukyukaghir
Y
5

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. alt text

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 "@.

Yukyukaghir answered 9/3, 2009 at 12:43 Comment(2)
As always mate, you'ce cracked it, I hadnt even heard of here-strings! Thanks again!Helenehelenka
Ah, glad to hear that I was able to spread the power of hear-strings. It is great to spread powershell's functionalities ;)Yukyukaghir
C
1

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.

Cloe answered 22/3, 2009 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.