title: Trying to get a Powershell Script that will run in a 2nd window and monitor in real time other running scripts / report all Errors / ExitCodes
body: <p>I am fairly new to writing code in Powershell.  For my job I have to write multiple Powershell scripts to make changes in the Hardware and Software settings as well as the Registry and Group Policy Editor to get these applications to run.  These applications are a little older.  Upgrading these software applications or the hardware then run on is NOT an option.  as an example, when Microsoft releases the new patches on like Patch Tuesday...when those patches are applied there is a high probability that something will be changed which is where I come in to write a script to fix the issue.  I have multiple scripts that I run.  When those scripts are ran they may end up terminating because of an Error Code or an Exit Code.  A large part of the time I do not that the script has failed immediately.</p>
  <p>I am trying to figure out a script that I can run in a 2nd PowerShell Console Window.  I am thinking that the only purpose of this script is to just sit there on the screen and wait and monitor.  Then when I execute a script or Application (the only file extensions that I am worried about are:   EXE, BAT, CMD, PS1) if the script/application that I just ran ends with an exit code or an error code....then output that to the screen...in REAL TIME.</p>
  <p>Below, I have a small piece of code that kind of works, but it is not what I am wanting.
  I have researched online and read and read tons of stuff.  But I just can't seem to find what I am looking for.
  Could someone please help me with getting a script that will do what I am wanting.</p>
  <p>Thank you for your help!!!!</p>
  <pre><code>$ExitErrorCode = 
  &quot;C:\ThisFolder\ThatFolder\AnotherFolder\SomeApplication.EXE # (this 
  would 
             # either be an EXE or CMD or BAT or PS1)&quot;
  $proc = Start-Process $ExitErrorCode -PassThru
  $handle = $proc.Handle # cache proc.Handle
  $proc.WaitForExit();
  
  if ($proc.ExitCode -ne 0) {
      Write-Warning &quot;$_ exited with status code $($proc.ExitCode)&quot;
  }
  </code></pre>