Test $lastexitcode from start-process of robocopy

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

Viewing 2 reply threads
  • Author
    Posts
    • #145415
      Participant
      Topics: 1
      Replies: 0
      Points: 38
      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
      Senior Moderator
      Topics: 9
      Replies: 1236
      Points: 4,443
      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: 590
      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
      
      
Viewing 2 reply threads
  • The topic ‘Test $lastexitcode from start-process of robocopy’ is closed to new replies.