Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run PowerShell command (with pipeline) in CMD

When we run the following command in PowerShell:

get-date | sc C:\temp\date.log

it creates date.log file with current date.

But if we run the same via CMD:

powershell get-date | sc C:\temp\date.log

It complains:

ERROR: Unrecognized command

DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...

Apparently, CMD confuses pipeline meant for POSH, with its own.

Can anyone point me how to make it run via CMD?

Thanks in anticipation.

like image 576
Annie Avatar asked Dec 27 '13 13:12

Annie


Video Answer


1 Answers

powershell -Command " & {Get-Date | sc c:\tmp\date.log}"

CMD and PowerShell

like image 102
juanvan Avatar answered Sep 20 '22 05:09

juanvan