Instead of exiting the process, try it this way:
param(
[string]$logfile,
[string]$sourceFile,
[string]$destinationFile
)
("PID ${PID} started at " + (Get-Date)) | Out-File -Filepath $logfile -Append
Try{
Move-Item -Path $sourceFile -Destination $destinationFile -Force -ErrorAction Stop 2>&1 | Out-File -Filepath $logfile -Append
("PID ${PID} ended at " + (Get-Date)) | Out-File -Filepath $logfile -Append
$LASTERRORCODE = 0
}
Catch{
("PID ${PID} ERROR at $(Get-Date) :`n$_") | Out-File -FilePath $logfile -Append
$LASTERRORCODE = 1
}
I added the try/catch (and changed the "Continue" to "Stop" in the erroraction parameter).