Hei
$exitcode = Start-Process -FilePath $RobocopyPath -ArgumentList $RobocopyOptions -Wait -NoNewWindow -PassThru
$lastexitcode = $exitcode.ExitCode
if (($lastexitcode -eq 1)) {
Write-Verbose"Copy from [$SourcePath] to [$DestinationPath] completed successfully with exit code: [$lastexitcode] One of more files were copied successfully."
}
Struggling with trying capture and test $lastexitcode from pester. Any help much appreciated.
what error you are getting ? and how are you testing it. Please share you code or a sample one.
I was able to get a successful run by using this:
[pre]
Describe 'robocopy' {
It 'Should return 0 or 1 on LASTEXITCODE' {
$Source=New-Item TestDrive:\Temp -ItemType Directory
$Destination=New-Item TestDrive:\Test -ItemType Directory
robocopy $Source $Destination -E
$LASTEXITCODE|Should BeLessOrEqual 1
}
}
[/pre]
Result:
[pre]
Executing all tests in ‘C:\temp’
Executing script C:\temp\Robocopy.Tests.ps1
Describing robocopy
[+] Should return 0 or 1 on LASTEXITCODE 31ms
Tests completed in 143ms
Tests Passed: 1, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0
[/pre]