无法将“ copy-item”识别为内部或外部命令

时间:2019-05-10 07:38:19

标签: powershell cmd

我对此有疑问:

  

'copy-item'不被识别为内部或外部命令

我该如何解决?

system ("start powershell  get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'")

1 个答案:

答案 0 :(得分:7)

问题是因为您将单个命令运行整个字符串"start powershell get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'

它的作用是先运行命令start powershell get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf,然后在运行命令后运行copy-item -Destination 'C:\22'。现在copy-item在CMD中显然不存在,因此引发了错误。

您需要将字符串get-Childitem -Path 'D:\Program Files\12' -recurse -filter *.dxf | copy-item -Destination 'C:\22'用引号引起来,以便将整个字符串交给powershell来运行。

作为一个简单的示例,命令start powershell Get-ChildItem | write-output失败,但是命令start powershell "Get-ChildItem | write-output"可以正常工作。

相关问题