在CMD中运行PowerShell命令(带有管道)
问题描述:
在PowerShell中运行以下命令时:
When we run the following command in PowerShell:
get-date | sc C:\temp\date.log
它使用当前日期创建date.log文件。
it creates date.log file with current date.
但是如果我们通过CMD运行相同的命令:
But if we run the same via CMD:
powershell get-date | sc C:\temp\date.log
它抱怨:
错误:无法识别的命令
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>...
显然,CMD混淆了管道的含义
Apparently, CMD confuses pipeline meant for POSH, with its own.
有人可以指出我如何通过CMD运行它吗?
Can anyone point me how to make it run via CMD?
谢谢