使用netshlogging窗口连接

我正在尝试使用Vista x64上的netsh启用连接日志logging,如此MSDN文章中有关防火墙故障排除 …

首先,我启用了允许的连接logging到%systemroot%\system32\LogFiles\Firewall\pfirewall.log ,下面…

 PS C:\Windows\system32> netsh advfirewall set allprofiles logging allowedconnections enable Ok. PS C:\Windows\system32> 

接下来我检查是否真的启用了日志logging。 AFAICT,这是…

 PS C:\Windows\system32> netsh advfirewall show currentprofile Public Profile Settings: ---------------------------------------------------------------------- State ON Firewall Policy BlockInbound,AllowOutbound LocalFirewallRules N/A (GPO-store only) LocalConSecRules N/A (GPO-store only) InboundUserNotification Enable RemoteManagement Disable UnicastResponseToMulticast Enable Logging: LogAllowedConnections Enable LogDroppedConnections Disable FileName %systemroot%\system32\LogFiles\Firewall\pfirewall.log MaxFileSize 4096 Ok. PS C:\Windows\system32> 

但是,当我尝试检索日志,我不能…

 PS C:\Windows\system32> Get-Content %systemroot%\system32\LogFiles\Firewall\pfirewall.log Get-Content : Cannot find path 'C:\Windows\system32\%systemroot%\system32\LogFiles\Firewall\pfi oes not exist. At line:1 char:12 + Get-Content <<<< %systemroot%\system32\LogFiles\Firewall\pfirewall.log + CategoryInfo : ObjectNotFound: (C:\Windows\syst...l\pfirewall.log:String) [Get-C ception + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand PS C:\Windows\system32> 

我还需要做什么来启用从PowerShell的连接日志logging? 如果可能的话,我想避免重新启动。

正如你所看到的,当你检索日志文件时,你的%systemroot%variables在PowerShell中没有得到正确parsing:找不到path'C:\ Windows \ system32 \%systemroot%\ system32 \ LogFiles \ Firewall \ pfioes不存在。

在PowerShell中,通过执行以下命令来访问环境variables: $env:Variable

请试试这个命令:

Get-Content $env:systemroot\system32\LogFiles\Firewall\pfirewall.log