how i can run this command from cmd :
powershell.exe “(get-process | ? {$_.Description -eq “Sysinter Process Explorer”}) | select processname | out-file $env:APPDATAexample.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:APPDATAexample.txt + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : ExpectedValueExpression
Solution:
powershell -command "get-process | ? {$_.Description -eq 'Sysinter Process Explorer'} | select processname | out-file $env:APPDATAexample.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