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
Post a Comment