*scratches head*
Why make it hard?
I changed the header from
#Version: 1.5
#Software: Microsoft Windows Firewall
#Time Format: Local
#Fields: date time action protocol src-ip dst-ip src-port dst-port size tcpflags tcpsyn tcpack tcpwin icmptype icmpcode info path
2021-03-27 18:54:41 DROP UDP 192.168.231.149 192.168.231.255 40533 15600 63 - - - - - - - RECEIVE
To
date time action protocol src-ip dst-ip src-port dst-port size tcpflags tcpsyn tcpack tcpwin icmptype icmpcode info path
2021-03-27 18:54:41 DROP UDP 192.168.231.149 192.168.231.255 40533 15600 63 - - - - - - - RECEIVE
That’s it.
$c = import-csv -path .\p.log -Delimiter ( [char]32 ) -Encoding ascii
$c | where { $_.'dst-port' -eq 443 -and $_.'dst-ip' -notlike '172.217.7.*' }
Works perfectly well. Note that I had to fix your “notlike” clause.
If you want to remove the dashes (and therefore the quotes) it still works. It’s just a bit more work on the header.
$c | where { $_.dstport -eq 443 -and $_.dstip -notlike '172.217.7.*' }
Regards,
Michael B.
--
You received this message because you are subscribed to the Google Groups "ntpowershell" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ntpowershell...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ntpowershell/CADy1Ce4P7EUTHRazbGDEaXe6Pq%3DRU97EopTwFGB_QQab7%2BopTw%40mail.gmail.com.
Here's another approach to avoid needing to remove the comments or edit the log file:
$FirewallHeaders = 'date time action protocol src-ip dst-ip src-port dst-port size tcpflags tcpsyn tcpack tcpwin icmptype icmpcode info path'.split(' ')
Get-Content 'C:\Windows\System32\LogFiles\Firewall\pfirewall.log' | ConvertFrom-Csv -Delimiter ' ' -Header $FirewallHeaders | Out-GridView
-Aakash Shah
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/CADy1Ce42Z6mdcEhyk1MCRiMhp97V50VjhtJ9C0qRrnvA9-Odpw%40mail.gmail.com.
Thank you for this. So much better to review firewall logs.
From: ntpowe...@googlegroups.com <ntpowe...@googlegroups.com>
On Behalf Of Aakash Shah
Sent: Saturday, March 27, 2021 7:13 PM
To: ntpowe...@googlegroups.com
Subject: [SOCIAL NETWORK] RE: [ntpowershell] Parsing Windows Firewall logs
*** External email - Exercise caution ***
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/BYAPR06MB5685710CCC5C91AF231A99E0F27F9%40BYAPR06MB5685.namprd06.prod.outlook.com.
Sure!
I forgot to mention that I used Get-Content here instead of Import-Csv since we can use the -Tail parameter to keep refreshing the display with new entries. So for instance if you’re monitoring for something, you can use something like this:
Get-Content 'C:\Windows\System32\LogFiles\Firewall\pfirewall.log' -Tail 1 -Wait | ConvertFrom-Csv -Delimiter ' ' -Header $FirewallHeaders | Where-Object {$_.'dst-port' -eq '443'} | Format-Table
Also note not to use the -AutoSize parameter with Format-Table since I found it didn’t return any results.
-Aakash Shah
To view this discussion on the web visit https://groups.google.com/d/msgid/ntpowershell/SA1PR09MB80328CA3E2D7E061FDAFCF398E7C9%40SA1PR09MB8032.namprd09.prod.outlook.com.