Number of files processed by Copy-Item not working with –FromSession parameter?

Hi,

I have the following script that works great and return the number of files processed by Copy-Item,
however, if I use the -Fromsession parameter it will always return 0 files even though some of the files
have been processed successfully:

Copy-Item –Path C:\ShadowCopy\temp\* –Destination D:\Test\ –Recurse -force -PassThru -ErrorAction silentlyContinue |
Measure-Object | Select-Object -Expand Count |
Tee-Object -Variable file_count | Out-Null

if ($file_count -ge "1") {
Write-Host "Number of files processed: $file_count"
}
else { 
Write-Host $error[0].exception.message -ForegroundColor Red
}

This script is NOT working:

$Session = New-PSSession -ComputerName PC_NAME -EA 1

Copy-Item –Path C:\ShadowCopy\temp\* –FromSession $Session –Destination D:\Test\ –Recurse -force -PassThru -ErrorAction silentlyContinue |
Measure-Object | Select-Object -Expand Count |
Tee-Object -Variable file_count | Out-Null

if ($file_count -ge "1") {
Write-Host "Number of files processed: $file_count"
}
else { 
Write-Host $error[0].exception.message -ForegroundColor Red

}

 

What am I missing?

 

 

Copy item doesn’t Passthru when copying from/to sessions.

As a workaround do a Get-ChildItem on the local copy of the files and return the count

Thanks, that explain why it is not working then.