如何使用 PowerShell 獲取 Windows 防火牆配置檔案設定?


Windows 10、Windows Server 2008 等最新的 Windows 客戶端和伺服器作業系統支援高階防火牆版本,且主要有 3 個配置檔案。

  • 公用

  • 專用配置檔案。

要使用 GUI 獲取設定,則需要在框中搜索高階安全 Windows 防火牆高階安全 Windows Defender 防火牆。隨後你可以在控制檯中看到 3 個可用的配置檔案。

同上個設定,可以使用 PowerShell Get-NetFirewallProfile 命令檢視。

PS C:\> Get-NetFirewallProfile
Name : Domain
Enabled : True
DefaultInboundAction : NotConfigured
DefaultOutboundAction : NotConfigured
AllowInboundRules : NotConfigured
AllowLocalFirewallRules : NotConfigured
AllowLocalIPsecRules : NotConfigured
AllowUserApps : NotConfigured
AllowUserPorts : NotConfigured
AllowUnicastResponseToMulticast : NotConfigured
NotifyOnListen : True
EnableStealthModeForIPsec : NotConfigured
LogFileName : %systemroot%\system32\LogFiles\Firewall\pfirewall.log
LogMaxSizeKilobytes : 4096
LogAllowed : NotConfigured
LogBlocked : NotConfigured
LogIgnored : NotConfigured
DisabledInterfaceAliases : {NotConfigured}
Name : Private
Enabled : True
DefaultInboundAction : NotConfigured
DefaultOutboundAction : NotConfigured
AllowInboundRules : NotConfigured
AllowLocalFirewallRules : NotConfigured
AllowLocalIPsecRules : NotConfigured
AllowUserApps : NotConfigured
AllowUserPorts : NotConfigured
AllowUnicastResponseToMulticast : NotConfigured
NotifyOnListen : True
EnableStealthModeForIPsec : NotConfigured
LogFileName : %systemroot%\system32\LogFiles\Firewall\pfirewall.log
LogMaxSizeKilobytes : 4096
LogAllowed : NotConfigured
LogBlocked : NotConfigured
LogIgnored : NotConfigured
DisabledInterfaceAliases : {NotConfigured}
Name : Public Enabled : True
DefaultInboundAction : NotConfigured
DefaultOutboundAction : NotConfigured
AllowInboundRules : NotConfigured
AllowLocalFirewallRules : NotConfigured
AllowLocalIPsecRules : NotConfigured
AllowUserApps : NotConfigured
AllowUserPorts : NotConfigured
AllowUnicastResponseToMulticast : NotConfigured
NotifyOnListen : True
EnableStealthModeForIPsec : NotConfigured
LogFileName : %systemroot%\system32\LogFiles\Firewall\pfirewall.log
LogMaxSizeKilobytes : 4096
LogAllowed : NotConfigured
LogBlocked : NotConfigured
LogIgnored : NotConfigured
DisabledInterfaceAliases : {NotConfigured}

輸出為詳細資訊檢視。如果你只需要檢視配置檔名稱和是否啟用,則使用 select 命令即可。

Get-NetFirewallProfile | Select Name, Enabled

輸出

Name Enabled ---- ------- Domain True Private True Public True

同樣地,你可以根據你的要求過濾上述輸出中的不同引數。

若要在遠端計算機上獲取設定,則需要使用Invoke-CommandPSSession,因為此命令不支援直接使用-ComputerName引數。

Invoke-Command -ComputerName RemoteServerName -ScriptBlock{ Get-NetFirewallProfile | Select Name, Enabled}

更新於: 2020-09-28

2K+ 瀏覽量

開啟你的職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.