2

Get-NetFirewallProfilecmdlet 具有该计算机-PolicyStore ActiveStore上所有策略的总和的选项。当我运行它时,我得到考虑 GPO 的防火墙配置文件状态。

Get-CimInstance -Namespace Root\StandardCimv2 -ClassName MSFT_NetFirewallProfile或者,我可以使用or获取 CIM 实例Get-WmiObject -Namespace "Root\StandardCimv2" -Query "SELECT * FROM MSFT_NetFirewallProfile",但 GPO 值被丢弃。

如何在 中设置策略存储Get-WmiObject -Namespace "Root\StandardCimv2" -Query "SELECT * FROM MSFT_NetFirewallProfile"

最后,我将使用wbemcli api在 c++ 中实现查询

4

1 回答 1

1


您可以使用 IWbemContext 指定 PolicyStore 参数。以下是说明其使用的代码示例:

电源外壳:

$CimSession = New-CimSession
$options = New-Object Microsoft.Management.Infrastructure.Options.CimOperationOptions
$options.SetCustomOption("PolicyStore", "ActiveStore", $true)
$CimSession.EnumerateInstances("Root\StandardCimv2", "MSFT_NetFirewallProfile", $options)

VB:

strComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\StandardCimv2")

Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "PolicyStore", "ActiveStore"

Set colSWbemObjectSet = objSWbemServices.InstancesOf("MSFT_NetFirewallProfile",,objCtx)
For Each objSWbemObject In colSWbemObjectSet
Wscript.Echo "Enabled: " & objSWbemObject.Enabled
Next
于 2020-03-09T11:23:19.127 回答