Get-NetFirewallProfile
cmdlet具有选项-PolicyStore ActiveStore
,它是该计算机上所有策略的总和。当我运行它时,我会考虑使用GPO的防火墙配置文件状态。
或者,我可以使用Get-CimInstance -Namespace Root\StandardCimv2 -ClassName MSFT_NetFirewallProfile
或Get-WmiObject -Namespace "Root\StandardCimv2" -Query "SELECT * FROM MSFT_NetFirewallProfile"
获得CIM实例,但是GPO值将被丢弃。
如何在Get-WmiObject -Namespace "Root\StandardCimv2" -Query "SELECT * FROM MSFT_NetFirewallProfile"
中设置策略存储?
最后,我将使用wbemcli api在c++中实现查询
最佳答案
您可以使用IWbemContext指定PolicyStore参数。以下是说明其用法的代码示例:
电源 shell :
$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
关于powershell - 在CIM实例中设置PolicyStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60476758/