Use Psexec to Run Robocopy

Use Psexec to Run Robocopy

Hi I'm currently making a script that copies a directory to another. I'm currently using this:

robocopy $splunkconfig 'C:\Program Files\SplunkUniversalForwarder\etc\apps' /is /it /copyall /mir

But when I tried to combine it with psexec I'm having trouble making it work. Here's what I've tried so far:

Start-Process -FilePath $PSExecExePath -ArgumentList @("\\$computer -e -s cmd.exe /c", "robocopy $splunkconfig \\$computer\c$\Program Files\SplunkUniversalForwarder\etc\apps /is /it /copyall /mir")

and

Start-Process -FilePath $PSExecExePath -ArgumentList @("\\$computer -e -s cmd.exe /c", "`"robocopy $splunkconfig \\$computer\c$\Program Files\SplunkUniversalForwarder\etc\apps /is /it /copyall /mir`"")

Any help would be great. thank you!!

3

1 Answer

Try this:

psexec.exe \\$computer -c "robocopy $splunkconfig 'C:\Program Files\SplunkUniversalForwarder\etc\apps' /is /it /copyall /mir"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.