WQL——用于PowerShell中获取WMI对象的查询语言
2020-12-11 18:08
1646 查看
WQL 语言
1、WQL是什么?
WQL是用于获取PowerShell中的WMI(Windows Management Instrumentation)对象的WMI查询语言(WQL)。
2、为什么要用WQL语言?
WQL 查询比标准 Get-WmiObject 命令要快一些,而且在数百个系统上运行命令时,性能得到了改善。
3、如何引用WQL语句?
WQL查询语句可以接在“Get-WmiObject”和“Get-CimInstance”后使用,结构如下
Get-WmiObject -Query "<WQL Query> "
Get-CimInstance -Query "<WQL Query>"
WQL查询语句的基本结构:
Select <property> from <WMI-class> [where <property> <operator> <value>]
例子:查询Notepad进程的详细信息
使用Get-WmiObject
Get-WmiObject -Query {Select * from Win32_Process where Name = 'Notepad.exe'}
命令输出:
__GENUS : 2 __CLASS : Win32_Process __SUPERCLASS : CIM_Process __DYNASTY : CIM_ManagedSystemElement __RELPATH : Win32_Process.Handle="5444" __PROPERTY_COUNT : 45 __DERIVATION : {CIM_Process, CIM_LogicalElement, CIM_ManagedSystemElement} __SERVER : SZ-Test1119 __NAMESPACE : root\cimv2 __PATH : \\SZ-GADZ050761\root\cimv2:Win32_Process.Handle="5444" Caption : notepad.exe CommandLine : "C:\WINDOWS\system32\notepad.exe" CreationClassName : Win32_Process CreationDate : 20201211175155.893933+480 CSCreationClassName : Win32_ComputerSystem CSName : SZ-Test1119 Description : notepad.exe ExecutablePath : C:\WINDOWS\system32\notepad.exe ExecutionState : Handle : 5444 HandleCount : 238 InstallDate : KernelModeTime : 781250 MaximumWorkingSetSize : 1380 MinimumWorkingSetSize : 200 Name : notepad.exe OSCreationClassName : Win32_OperatingSystem OSName : Microsoft Windows 10 企业版|C:\WINDOWS|\Device\Harddisk0\Partition2 OtherOperationCount : 110 OtherTransferCount : 2584 PageFaults : 4035 PageFileUsage : 3108 ParentProcessId : 3980 PeakPageFileUsage : 3108 PeakVirtualSize : 2203492605952 PeakWorkingSetSize : 15484 Priority : 8 PrivatePageCount : 3182592 ProcessId : 5444 QuotaNonPagedPoolUsage : 14 QuotaPagedPoolUsage : 244 QuotaPeakNonPagedPoolUsage : 14 QuotaPeakPagedPoolUsage : 244 ReadOperationCount : 1 ReadTransferCount : 60 SessionId : 1 Status : TerminationDate : ThreadCount : 7 UserModeTime : 0 VirtualSize : 2203492605952 WindowsVersion : 10.0.19042 WorkingSetSize : 15851520 WriteOperationCount : 0 WriteTransferCount : 0 PSComputerName : SZ-GADZ050761 ProcessName : notepad.exe Handles : 238 VM : 2203492605952 WS : 15851520 Path : C:\WINDOWS\system32\notepad.exe
使用Get-CimInstance
Get-CimInstance -Query "Select * from CIM_Process where Name = 'Notepad.exe'"
命令输出:
ProcessId Name HandleCount WorkingSetSize VirtualSize --------- ---- ----------- -------------- ----------- 5444 notepad.exe 237 15912960 2203472412672
使用 “Get-CimInstance -Query” 的时候,后面的 WQL查询语句,不要用{},需要用""括起来,否则会报错。
注:使用 { }括起来的时候被作为脚本块解析了,脚本块中的 WQL没有输入。
PS C:\> Get-CimInstance -Query {Select * from Win32_Process where Name = 'Notepad.exe'} Get-CimInstance : 无法评估参数“Query”,因为其参数被指定为脚本块,且没有输入。无法评估没有输入的脚本块。 所在位置 行:1 字符: 24 + ... tance -Query {Select * from Win32_Process where Name = 'Notepad.exe'} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : MetadataError: (:) [Get-CimInstance], ParameterBindingException + FullyQualifiedErrorId : ScriptBlockArgumentNoInput,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInsta nceCommand
附 WQL查询语言中Where语句中有效的运算符:
Operator Description ----------------------- = Equal != Not equal <> Not equal < Less than > Greater than <= Less than or equal >= Greater than or equal LIKE Wildcard match IS Evaluates null ISNOT Evaluates not null ISA Evaluates a member of a WMI class
相关文章推荐
- PowerShell 2.0之使用WMI管理Windows(三)对WMI对象的语言支持
- PowerShell 2.0之使用WMI管理Windows(三)对WMI对象的语言支持
- powershell 获取wmi对象
- PowerShell 2.0之使用WMI管理Windows(三)对WMI对象的语言支持
- Jmeter Beanshell 获取响应信息头部时间,更改时间格式用于JDBC查询条件
- C#中通过WMI的Win32_DiskDrive对象获取磁盘驱动器信息
- C# 利用WMI对象获取物理内存和可用内存大小
- OC语言学习 (四) SEL对象,用于日志输出的宏
- PHP使用mysql_fetch_object从查询结果中获取对象集的方法
- Java数据对象JDO 2.0查询语言的特点
- NQL.NET 数据库对象查询语言简介 2
- WMI 管理对象的信息查询和方法访问
- EventSource 对象用于接收服务器发送事件通知,是网页自动获取来自服务器的更新
- 第04天OC语言(17):获取类对象及类对象应用场景
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- Java虚拟机性能监测工具Visual VM与OQL对象查询语言
- MySQL提供了以下三种方法用于获取数据库对象的元数据:
- 接口 CommonDao(根据指定的PO类、多个查询条件、排序字段及开始位置、查询总数量来获取po对象列表 findAllByPropertys)
- C#中通过WMI的Win32_Processor对象获取CPU信息简介
- mybatis查询得到list列表,列表长度不为零,但遍历列表获取对象属性值时,出现空指针异常