Search code examples
powershellcopy

Copy-Item: A positional parameter cannot be found that accepts argument '+'


Can anyone help me with this error? What is wrong in this command line from image?

copy /b file.msi + malicious.jar newfile.jar

PowerShell Image


Solution

  • You're trying to use cmd.exe's copy command, which is an internal command to cmd.exe (not a separate executable). As such, you can only call it via cmd /c from PowerShell.

    By contrast, copy, when called directly from PowerShell, is a built-in alias that refers to PowerShell's Copy-Item cmdlet, whose invocation syntax and supported parameters differ fundamentally from cmd.exe's internal copy command.

    Copy-Item does not support merging multiple files (+) as binary files (/b), so you'll have to call cmd.exe's copy command, via cmd /c:

    cmd /c 'copy /b file.msi + malicious.jar newfile.jar'