Saturday 23 September 2017

windows - run powershell command from cmd


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




Answer



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


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...