powershell - 在CIM实例中设置PolicyStore

标签 powershell wmi wbem cim

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++中实现查询

最佳答案

您可以使用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/

相关文章:

wbem - 提供符合 SMI-S 的客户端 API 的 CIM/WBEM 包

c++ - 来自 IWbemClassObject::Get 的未知异常

Powershell 传递命令开关作为变量

windows - PowerShell数组在使用Send-MailMessage时未在电子邮件中显示空格('n),而在使用import-csv时在顶部显示*

.net - 获取附加到 Windows Server 2019 的磁盘序列号

powershell - 停止单引号转义 WMI 查询 powershell 中的字符串

c# - ManagementScope 能否用于从 Windows 向 Linux/MacOS 客户端发送 wbem 查询? C#

powershell - 从命令行使用 Azure 开发存储

Powershell 奇怪的错误处理行为

c# - 访问自定义 WMI 提供程序无限期挂起