0

I want to execute following power shell script from C# code

Add-Content D:\f.txt "Import Module"
Add-Content D:\f.txt "Remove Module"
Add-Content D:\f.txt "The End"
exit 4

I can execute the script from the C# code successfully.

I want my C# program to read the exit value (i.e. 4) returned from the powershell.

Can you please let me know how I can achieve it? Note: I am new to C# and powershell.

Cristian Lupascu
  • 39,078
  • 16
  • 100
  • 137
AjitB
  • 1
  • 2
  • 7
    Please show us the C# code how you execute the script. The Powershell code itself is not much of interest for answering your question. – Doc Brown Oct 29 '12 at 07:30
  • possible duplicate of [How to read PowerShell exit code via c#](http://stackoverflow.com/questions/12895503/how-to-read-powershell-exit-code-via-c-sharp) – Thom Smith Oct 29 '12 at 16:25

1 Answers1

0

same probleam as How to read PowerShell exit code via c#, it seems that you need to try alternative approach like PowerShell.Streams.Error or Runspace.RunspaceStateInfo rather than exit code.

Community
  • 1
  • 1
Jackie
  • 2,476
  • 17
  • 20