none
Getting Exit Code from Start-Process RRS feed

  • Question

  • How can I get the exit code from the following PowerShell command?:

    Start-Process -FilePath "C:\Windows\System32\robocopy.exe" -ArgumentList "C:\Bogus Folder","C:\Target",/MIR -Wait
    
    The above example should return an exit code of 16.

    Tuesday, November 9, 2010 1:35 AM

Answers

  • PS>$new = Start-Process -FilePath "C:\Windows\System32\robocopy.exe" -ArgumentList "C:\Bogus Folder","C:\Target",/MIR -Wait -PassThru
    PS>$new
    
    Handles NPM(K) PM(K)  WS(K) VM(M) CPU(s)  Id ProcessName
    ------- ------ -----  ----- ----- ------  -- -----------
        0  0   0  0  0.02 7076
    
    
    PS>$new.ExitCode
    16

    or

    PS> (Start-Process -FilePath "C:\Windows\System32\robocopy.exe" -ArgumentList "C:\Bogus Folder","C:\Target",/MIR -Wa
    it -PassThru).ExitCode
    16


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook

    • Marked as answer by nrogers64 Tuesday, November 9, 2010 4:28 AM
    Tuesday, November 9, 2010 4:06 AM

All replies

  • PS>$new = Start-Process -FilePath "C:\Windows\System32\robocopy.exe" -ArgumentList "C:\Bogus Folder","C:\Target",/MIR -Wait -PassThru
    PS>$new
    
    Handles NPM(K) PM(K)  WS(K) VM(M) CPU(s)  Id ProcessName
    ------- ------ -----  ----- ----- ------  -- -----------
        0  0   0  0  0.02 7076
    
    
    PS>$new.ExitCode
    16

    or

    PS> (Start-Process -FilePath "C:\Windows\System32\robocopy.exe" -ArgumentList "C:\Bogus Folder","C:\Target",/MIR -Wa
    it -PassThru).ExitCode
    16


    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    PowerShell 2.0 remoting - eBook

    • Marked as answer by nrogers64 Tuesday, November 9, 2010 4:28 AM
    Tuesday, November 9, 2010 4:06 AM
  • Excellent! Thank you!
    Tuesday, November 9, 2010 4:28 AM