Test $lastexitcode from start-process of robocopy

Welcome Forums Pester Test $lastexitcode from start-process of robocopy

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
2 months, 3 weeks ago.

  • Author
    Posts
  • #145415

    Participant
    Topics: 1
    Replies: 0
    Points: 12
    Rank: Member

    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.

  • #148965

    Moderator
    Topics: 8
    Replies: 891
    Points: 2,749
    Helping Hand
    Rank: Community Hero

    what error you are getting ? and how are you testing it. Please share you code or a sample one.

  • #149114

    Participant
    Topics: 0
    Replies: 113
    Points: 589
    Helping Hand
    Rank: Major Contributor

    I was able to get a successful run by using this:

    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
         }
    }

    Result:

    
    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
    
    

You must be logged in to reply to this topic.