11

how i can run this command from cmd :

powershell.exe "(get-process | ? {$_.Description -eq "Sysinter Process Explorer"}) | select processname | out-file $env:APPDATA\example.txt"

i still get this error :

You must provide a value expression on the right-hand side of the '-eq' operato r. At line:1 char:37 + (get-process | ? {$_.Description -eq <<<< Sysinternals Process Explorer}) | select processname | out-file $env:APPDATA\example.txt + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : ExpectedValueExpression

  • 3
    Your problem might be your inner set of quotation marks. Try either removing them or if they must be used, try using this guy: ' aka the apostrophe in place. – DeathByTensors May 24 '16 at 11:15
  • 1
    Warning - please do not use obscenities in your posts. I've removed it for you. Note that other users may have flagged your post as "rude or abusive" leading to possible rep loss or suspension. Please read Be Nice: "Avoid vulgar terms and anything sexually suggestive" – DavidPostill May 24 '16 at 11:43
19
powershell -command "get-process | ? {$_.Description -eq 'Sysinter Process Explorer'} | select processname | out-file $env:APPDATA\example.txt"

basically you have a powershell command and paste it in between these quotes to call it from CMD

powershell -command " #PasteCodeHere "

inside these quotes you have to work with ' otherwise it will interrupt your command parameter.

Edit: Additional Information:

quite often you will encounter this: powershell -command "& 'somestuff'"

the & is used to call a File. when you're only using a command & is unnessecary, when you want to call a script, you should use it.

powershell -command "& 'C:\foobar.ps1'"

You could also use powershell -file C:\file.ps1 to call a script

  • u are the best man <3 it's working – Qassam Mahmoud May 24 '16 at 15:46
  • 1
    If the command to be executed has quotes, they must be doubled. Example : powershell -command "dir ""c:\Program Files""" – Myobis Mar 29 '18 at 9:28
  • @myobis or you can just use single quotes powershell -command " dir 'C:\Program Files' " – SimonS Mar 29 '18 at 10:06
  • @myobis Actually, doubling the quotes doesn't work (in Windows 10 cmd). But using backslash escaping did: powershell -command "dir \"c:\Program Files\" " – wisbucky Apr 3 '18 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.