【问题标题】:set PolicyStore in CIM instance在 CIM 实例中设置 PolicyStore
【发布时间】:2020-06-14 00:51:14
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: powershell wmi wbem cim


    【解决方案1】:


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

    PowerShell:

    $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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-02
      • 2021-12-24
      • 2011-10-29
      • 2011-12-26
      • 1970-01-01
      • 2012-01-29
      • 2017-10-20
      • 1970-01-01
      相关资源
      最近更新 更多