'copy-item' is not recognized as an internal or external command

1 powershell cmd

I have problem with this:

'copy-item' is not recognized as an internal or external command

How can I fix it?

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

Sha*_*zee 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"可以按预期运行。