bea*_*gle 6 windows firewall powershell event-log cmd.exe
我一直在网上闲逛,但我似乎无法找到这个问题的明确答案。我被迫使用 PowerShell v2。我知道使用以下命令将为我提供所有防火墙规则的列表:
netsh advfirewall firewall show rule name=all
但是它让我得到这样的输出:
Rule Name: Core Networking - Teredo (ICMPv6-In)
---------- ------------------------------------
Enabled: Yes
Direction: In
Profiles: Domain,Private,Public
Grouping: Core Networking
LocalIP: Any
RemoteIP: Any
Protocol: ICMPv6
Type Code
128 Any
Edge traversal: No
Action: Allow
Run Code Online (Sandbox Code Playgroud)
我需要找到的是创建/启用规则的确切时间。这可能吗?或者,有没有办法设置临时(定时)Windows 防火墙规则?
*编辑:似乎确实没有办法使用 netsh 或特定于防火墙的 powerhshell v2 cmdlet 来执行此操作,但是我相信我的解决方案可能位于 /Applications and Services Logs/Microsoft/Windows/Windows Firewall With Advanced Security/事件 ID 为 2004/2006 下的防火墙日志。
****编辑:** 可以使用以下命令查看Instance ID 2004(防火墙已添加规则...):
Get-WinEvent -LogName "Microsoft-Windows-Windows Firewall With Advanced Security/Firewall" | Where-Object {$_.ID -eq "2004"}
*****编辑:** 就目前而言,以下命令是收集此信息的最快方法Measure-Command -Expression。如果您愿意,您可以修改开始/结束时间或将其完全删除:
Get-WinEvent -ErrorAction SilentlyContinue -FilterHashtable @{logname="Microsoft-Windows-Windows Firewall With Advanced Security/Firewall"; id=2004; StartTime=(Get-Date).AddMinutes(-5); EndTime=Get-Date}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 166
Ticks : 1662222
TotalDays : 1.92386805555556E-06
TotalHours : 4.61728333333333E-05
TotalMinutes : 0.00277037
TotalSeconds : 0.1662222
TotalMilliseconds : 166.2222
Run Code Online (Sandbox Code Playgroud)
并让您像这样输出(您可以通过将其管道化到以下内容来获取完整的消息文本Format-List:
ProviderName: Microsoft-Windows-Windows Firewall With Advanced Security
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
4/28/2014 2:42:26 PM 2004 Information A rule has been added to the Windows Firewall exception list....
4/28/2014 11:56:43 AM 2004 Information A rule has been added to the Windows Firewall exception list....
Run Code Online (Sandbox Code Playgroud)
更新的问题是:有没有办法获取此信息而不是Message列,获取Rule Name(下面的格式列表管道)
TimeCreated : 4/28/2014 10:50:54 AM
ProviderName : Microsoft-Windows-Windows Firewall With Advanced Security
Id : 2004
Message : A rule has been added to the Windows Firewall exception list.
Added Rule:
Rule ID: ...
Rule Name: Dummy rule
Origin: Local
Active: Yes
Direction: Inbound
Profiles: Private,Domain, Public
Action: Block
Application Path:
Service Name:
Protocol: Any
Security Options: None
Edge Traversal: None
Modifying User: ...
Modifying Application: ...
Run Code Online (Sandbox Code Playgroud)
预期输出将是这样的:
TimeCreated Rule Name
----------- ---------
4/28/2014 2:42:26 PM Dummy rule
4/28/2014 11:56:43 AM Dummy rule
Run Code Online (Sandbox Code Playgroud)
已经至少一天了,所以我认为可以回答我自己的问题(我认为我在错误的地方问了这个问题,可能更适合 Stack Overflow):
$Events = Get-WinEvent -ErrorAction SilentlyContinue -FilterHashtable @{logname="Microsoft-Windows-Windows Firewall With Advanced Security/Firewall"; id=2004}
ForEach ($Event in $Events) {
$eventXML = [xml]$Event.ToXml()
For ($i=0; $i -lt $eventXML.Event.EventData.Data.Count; $i++) {
Add-Member -InputObject $Event -MemberType NoteProperty -Force `
-Name $eventXML.Event.EventData.Data[$i].name `
-Value $eventXML.Event.EventData.Data[$i].'#text'
}
}
$Events | Format-Table -Property TimeCreated,RuleName -AutoSize
Run Code Online (Sandbox Code Playgroud)
输出看起来与我想要的完全一样:
TimeCreated RuleName
----------- --------
4/28/2014 2:42:26 PM Dummy Rule
4/28/2014 11:56:43 AM Dummy Rule
Run Code Online (Sandbox Code Playgroud)
希望这对将来的人有帮助。谢谢。
| 归档时间: |
|
| 查看次数: |
4923 次 |
| 最近记录: |