Better Powershell script for parsing webmail logs?


i looking better way parse webmail logs using powershell , use help. here sample of logs:

111.111.111.111, domain\john.smith, 5/14/2012, 0:00:00, w3svc1, servername, 111.222.333.444, 359, 427, 483, 200, 0, post, /microsoft-server-activesync, user=john.smith&deviceid=appl6789321&devicetype=iphone&cmd=ping&log=v4tnasnc:0a0c0d0fs:0a0c0d0sp:1c17i21921s1457906r0s0l900h0p,
222.222.222.222, will.smith@my.domain.com, 5/14/2012, 0:00:00, w3svc1, servername, 111.222.333.444, 62, 578, 340, 200, 0, post, /microsoft-server-activesync, cmd=sync&user=will.smith@my.domain.com&deviceid=motoa0000022fe9a&devicetype=motodroidx451&log=v4tcassc:0a0c0d0fs:0a0c0d0sp:1c3i2790s39850r0s0l0h0p,
333.333.333.333, my.domain.com\philip.smith, 5/14/2012, 0:00:00, w3svc1, servername, 111.222.333.444, 375, 427, 482, 200, 0, post, /microsoft-server-activesync, user=philip.smith&deviceid=applc5fh661wddp7&devicetype=iphone&cmd=ping&log=v4tnasnc:0a0c0d0fs:0a0c0d0sp:1c23i27319s1244772r0s0l900h0p,

i have looked @ few options parsing this, android devices seem break pattern depending on type of device is. curious if there way in powershell grab parts in bold. sure relatively simple task, still new powershell , have never used parse log file of nature. or links useful information appreciated.

you can same select-string:

$file = 'c:\webmail.log' # <- fully qualified path to your log $pattern = 'user=(.+)&deviceid=(.+)&devicetype=([^&]+)' select-string -pattern $pattern -path $file | foreach-object {   new-object psobject -property @{     user = $_.matches[0].groups[1]     deviceid = $_.matches[0].groups[2]     devicetype = $_.matches[0].groups[3]   } } 


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL