以下是一段连接到本地防火墙并转储所有打开的防火墙端口的 PowerShell 代码:
1 | $firewall = New-object -ComObject HNetCfg.FwPolicy2 |
结果看起来类似这样:
Name ApplicationName LocalPorts
---- --------------- ----------
pluginhost.exe C:\users\tobwe\appdata\local\skypeplugin\pluginhost.exe *
pluginhost.exe C:\users\tobwe\appdata\local\skypeplugin\pluginhost.exe *
spotify.exe C:\users\tobwe\appdata\roaming\spotify\spotify.exe *
spotify.exe C:\users\tobwe\appdata\roaming\spotify\spotify.exe *
在 Windows 10 和 Server 2016 中,有一系列现成的跟防火墙有关的 cmdlet:
1 | PS> Get-Command -Noun *Firewall* |
