Running applications such as robocopy.exe from PowerShell sometimes is not trivial. How do you submit arguments to the EXE so that PowerShell won't change them?
It really is simple: make sure all arguments are strings (so quote the arguments if they are no strings or contain spaces or other special characters). And, make sure you submit one string per argument, not one big string.
This would invoke robocopy.exe from PowerShell and copy all JPG pictures from the Windows folder to another folder c:\jpegs recursively, not retrying on errors, and skipping the folder *winsxs*:- $arguments = "$env:windir\", 'c:\jpegs\','*.jpg', '/R:0', '/S', '/XD', '*winsxs*'
- Robocopy.exe $arguments
复制代码 As you can see, the arguments are all strings, and they are submitted as a string array.
That works beautifully for each and every exe file you may ever want to invoke from PowerShell.
http://powershell.com/cs/blogs/tips/archive/2014/03/24/submitting-arguments-to-exe-files.aspx |