Search code examples
windowspowershellwmic

multiple parameters in wmic path win32_process get


I want to run this command wmic path Win32_Process get ParentProcessId, commandLine, creationdate, executablepath, name, processId with several parameters,but powershell swear at the syntax if I try to write comma-separated. What do I need to fix?


Solution

  • By default, the / cmdlets give you all the properties of a class on the object you receive, so you do not need to specify each one:

    $wmi = Get-WmiObject -Class Win32_Process
    $wmi | Get-Member -MemberType Property
    
    $props = 'ParentProcessId', 'CommandLine', 'CreationDate', 'ExecutablePath', 'Name', 'ProcessId'
    $wmi | Select-Object -Property $props
    

    As a best practice: if gives you a native abstraction (in this case, Get-WmiObject or Get-CimInstance), you should use it!