通过 Powershell 查找正在使用的防火墙

Find Firewall in use via Powershell

如何使用 Powershell 查找计算机上启用的防火墙的名称?

我不想知道防火墙是否启用,我只想知道它的名称,即您在控制中的安全和维护中看到的内容控制板。谢谢!

控制面板安全截图:

以下脚本在 Windows 10 版本 1809 上为我运行:

$computer   = '.'                                             # $env:COMPUTERNAME
$namespaces = "ROOT\SecurityCenter", "ROOT\SecurityCenter2"
$classname  = "FirewallProduct"
$ActiveFireWall = foreach ($namespace in $namespaces) {
    $aux = Get-WmiObject -Class $classname -Namespace $namespace -ComputerName $computer
    if ($aux) {
        $aux | Select-Object -Property [a-z]* -ExcludeProperty PSComputerName, 
                 Scope, Path, Options, ClassPath, Properties, SystemProperties, 
                 Qualifiers, Site, Container
    }
}
if ( $ActiveFireWall ) { $ActiveFireWall.displayName }