wmic 路径 win32_process 中的多个参数得到

multiple parameters in wmic path win32_process get

我想 运行 这个命令 wmic path Win32_Process get ParentProcessId, commandLine, creationdate, executablepath, name, processId 有几个参数,但是如果我尝试写逗号分隔的话,powershell 对语法发誓。我需要修复什么?

默认情况下,/ cmdlet 会为您提供您收到的对象的 class 的所有属性,因此您无需指定每个属性:

$wmi = Get-WmiObject -Class Win32_Process
$wmi | Get-Member -MemberType Property

$props = 'ParentProcessId', 'CommandLine', 'CreationDate', 'ExecutablePath', 'Name', 'ProcessId'
$wmi | Select-Object -Property $props

作为最佳实践:如果 为您提供原生抽象(在本例中为 Get-WmiObjectGet-CimInstance),您应该使用它!

逗号表示数组。如果你真的想要 wmic,你可以使用神奇的 "stop parsing" 运算符:

wmic --% path Win32_Process get ParentProcessId, commandLine, creationdate, executablepath, name, processId

Get-wmiobject 或 get-ciminstance 将输出更易于操作的对象。 Get-ciminstance 甚至在类名上有制表符补全,并通过管道连接到 select-object 或 where-object,您可以在属性上完成制表符补全。

get-ciminstance win32_process | select parentprocessId, commandLine, creationdate, executablepath, name, processId
get-ciminstance win32_process | where commandline -match chrome