I'm trying to pass som logparserarguments from powershell, just because i need to get the date right to be able to get the right data at the right time. But logparser wont accept the code from powershell, but if i run it directly from cmd without the needed date variable it works.
$date = Get-Date -UFormat "%y%m%d"
$exe = "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe"
$herestring = @"
"SELECT
date AS Date,
time as Time,
s-ip as Server-IP,
cs-uri-stem as Request-URI
FROM C:\Local\temp\S0000\u_ex$date*.log
WHERE cs-uri-stem LIKE '%/Microsoft-Server-ActiveSync/%'
-i:IISW3C -o:csv -q:off >c:\Local\test\Activesynccalls1.csv
"@
start-process $exe -ArgumentList $herestring
When passing this to logparser, logparser complains about "Error: Syntax Error: extra token(s) after query: '-i:IISW3C'
but when i add a quotationmark after ...tiveSync/%'"
. it wont even take the argument at all, but when using the same argument in cmd it works just fine.
That won't work for several reasons:
string[]
which is what -ArgumentList
wantsSELECT
is superfluous.-ArgumentList
won't work. Start-Process
does not start a shell cmd
but, the process directly.Also, you don't need Start-Process
at all, but can directly run LogParser.exe
(you could, but it is not necessary here).
What you could try is something like this:
$date = Get-Date -UFormat "%y%m%d"
$query = @"
SELECT date AS Date, time as Time, s-ip as Server-IP, cs-uri-stem as Request-URI
FROM C:\Local\temp\S0000\u_ex$date*.log
WHERE cs-uri-stem LIKE '%/Microsoft-Server-ActiveSync/%'
"@
& "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe" $query -i:IISW3C -o:csv -q:off > c:\Local\test\Activesynccalls1.csv