最近我发现可以WmiObject
像这样发出 sql 查询:
Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name='java.exe'"
我想进一步限制包含CommandLine
参数的输出,例如:
Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name='java.exe' AND CommandLine like '%glassfish%'"
或者
Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name='java.exe' AND CommandLine like '*glassfish*'"
但是,这不会返回任何答案。我如何在那里制定近似匹配查询?我当然可以
Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name='java.exe'" | Where-Object { $_.CommandLine -match "glassfish" }
但这看起来并不优雅。