1

Code Image

wmic with subcommand in sequence with powershell. (" wmic" then next line "csproduct", I Have pasted in powershell. the csproduct not pasted in powershell as subcommand.

mklement0
  • 382,024
  • 64
  • 607
  • 775

2 Answers2

0

You're pasting multiple lines, which are executed individually:

  • First, wmic alone is executed, which instantly causes it to enter the wmic REPL, where you can submit commands interactively.

  • It is only afterwards that PowerShell - which isn't in control while the wmic REPL is active - tries to paste the other line, csproduct; that is, you'll see this word pasted after exiting the REPL, typically with exit.


To simply execute the csproduct sub-command, place both wmic and csproduct on the same line and paste that: wmic csproduct

This will make wmic execute the sub-command, return its output and exit right after, returning control to PowerShell.

If your intent is to supply multiple subcommands, via strings or a file:

  • Via strings:
'csproduct', 'context' | wmic
  • Via a file:
'csproduct', 'context' > subcmds.txt

Get-Content subcmds.txt | wmic

However, note that this prints the REPL prompt before each subcommand, as well as one final time, so you may want to perform separate wmic calls, with the help of ForEach-Object:

Get-Content subcmds.txt | ForEach-Object { wmic $_ }

Taking a step back:

mklement0
  • 382,024
  • 64
  • 607
  • 775
0

Or this is the same thing in powershell, csproduct being a wmic class alias for win32_computersystemproduct, and you'll get an object output instead of text.

get-ciminstance win32_computersystemproduct

IdentifyingNumber : ABCDEFG
Name              : 4321AB5
Vendor            : LENOVO
Version           : ThinkCentre M92z
Caption           : Computer System Product
js2010
  • 23,033
  • 6
  • 64
  • 66