# Retrieval of Root namespacesgwmi-namespace"root"-Class"__Namespace"|SelectName# Enumeration of all namespaces (administrator privileges may be required)Get-WmiObject-Class"__Namespace"-Namespace"Root"-List-Recurse2> $null |select __Namespace |sort__Namespace# Listing of namespaces within "root\cimv2"Get-WmiObject-Class"__Namespace"-Namespace"root\cimv2"-List-Recurse2> $null |select __Namespace |sort__Namespace
在命名空间中可以使用以下命令列出类:
gwmwi-List-Recurse# Defaults to "root\cimv2" if no namespace specifiedgwmi-Namespace"root/microsoft"-List-Recurse
Get-WmiObject-Recurse-List-classwin32*|more# Defaults to "root\cimv2"gwmi-Namespace"root/microsoft"-List-Recurse-Class"MSFT_MpComput*"
调用一个类:
# Defaults to "root/cimv2" when namespace isn't specifiedGet-WmiObject-Classwin32_shareGet-WmiObject-Namespace"root/microsoft/windows/defender"-ClassMSFT_MpComputerStatus
方法
方法是 WMI 类的一个或多个可执行函数,可以被执行。
# Class loading, method listing, and execution$c = [wmiclass]"win32_share"$c.methods# To create a share: $c.Create("c:\share\path","name",0,$null,"My Description")
# Method listing and invocationInvoke-WmiMethod-Classwin32_share-NameCreate-ArgumentList@($null, "Description", $null, "Name", $null, "c:\share\path",0)
WMI枚举
WMI服务状态
用于验证WMI服务是否正常运行的命令:
# WMI service status checkGet-ServiceWinmgmt# Via CMDnetstart|findstr"Instrumentation"