# 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"