I have this powershell scrip where I want to copy files from our production server to our test server, and only have it copy files which are newer or changed. The script itself has many more functions but this copying is one of those. I'm using the following XCopy command for that:
... some other scriptingcode
try {
xCopy $source $destination /f /e /r /k /y /d
}
catch {
Write-Host "issue: $PSItem" -ForegroundColor Yellow -BackgroundColor Red
}
... some more other scriptingcode
When I run the XCopy
command directly from the powershell prompt it shows it's progress, the files being copied, while it's running, but when I run it from the script itself, it doesn't output anything. And just adding -Verbose
at the end just gives me a script error.
I've tried the following:
$output = $(xCopy $source $destination /f /e /r /k /y /d) -join "`r\`n"
Write-Host $output
But that only gives me the output after it's already been copied, and isn't a problem when no, 1 or 2 files are copied, but not really helpfull when you have a 100 or 1.000 files to copy. FYI, the -join "'r'n"
is because the output is an array when more than one line is output, so I had to join the lines into one string which could be shown by Write-Host
.
I have tried to google for a solution, but I guess my google skills aren't good enough to get me any results to this problem.
So, is there a way to have XCopy
output while it's doing it, just like directly from the powershell commandline?