parsing a firewall log file


i need writing powershell script

i saved firewall log text file on c:\temp\fw-log.

i need script parse text file , export information need csv file. csv file should contain following information....

date , time, action, protocol, src-ip, dst-ip, , port 445.

here example of information need.

date time action protocol src-ip dst-ip src-port dst-port size tcpflags tcpsyn tcpack tcpwin icmptype icmpcode info path

2013-02-08 08:30:48 allow tcp 113.525.68.124 113.525.018.22 50427 445 0 - 0 0 0 - - - send


rick


try this:

$firewalllog=get-content 'c:\temp\fw-log.txt'  $result=@()  foreach($logline in $firewalllog){     $logline=$logline -split ' '     if($logline[7] -eq '445'){         $result+=new-object psobject -property @{             'date'=$logline[0];             'time'=$logline[1];             'action'=$logline[2];             'protocol'=$logline[3];             'src-ip'=$logline[4];             'dst-ip'=$logline[5];             'dst-port'=$logline[7]         }     } } $result | select date,time,action,protocol,src-ip,dst-ip,dst-port | export-csv -notype 'c:\log.csv'


inspired carlsberg.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file