I'm having some trouble using RoboCopy.exe through a Powershell script. The function is as follows...
function copyFiles{
Start-Process "RoboCopy.exe" -ArgumentList "'C:\Test' 'C:\test2' /copyall"
Write-Host 'Test'
}
"Test" is output to console but the copy does not run. I was initially attempting to copy with variables as the directories, but I've boiled it down to this since that was not working. In the directory 'test1' there is a single .txt file and 'test2' exists but is empty. I have tried it without that directory existing as well.
It is called in another file via:
. .\rCopy.ps1
copyFiles
Now, I tried outputting the log to a file with the code below, but it gives me a permissions error. "Out-File : Access to the path 'C:\Users\Me\Desktop' is denied". I also tried outputting direct to C:\ but that gives the same error. Powershell IS running as administrator.
$testCopy = Start-Process "RoboCopy.exe" -ArgumentList "'C:\Test' 'C:\test2' /copyall"
$testCopy | Out-File -LiteralPath "C:\Users\Me\
And to close, I have also tried running "Start-Process 'RoboCopy.exe' -ArgumentList 'C:\test' 'C:\test2' /copyall" in the main script, without calling the function from another.
Any help would be greatly appreciated.