$dest ="C: est"
New-Item $dest -type directory -force
$source ="c:samplefile.txt"
Copy-Item $source $dest
exit $LASTEXITCODE // или возвращайте свой код ошибки
$LastExitCode
Contains the exit code of the last Windows-based program that was run.
try {
Copy-Item -ErorAction Stop .......
}
catch {
exit 1
}