title: write robocopy output to console and log file
body: <p>I have an interactive PowerShell using windows forms, meaning a PowerShell script displays some controls on a form asking for input and finally runs <code>robocopy</code>, when the user clicks the button.</p>
  
  <p>This is a simple script displaying the problem. 
  You can copy the code, save it to a Power Sell script and run. It needs a:\tmp\tmp folder to successfully run, see the CopyFolder function.</p>
  
  <pre><code>function createdMainForm {
      $mainForm = New-Object System.Windows.Forms.Form
  
      $btn = New-Object System.Windows.Forms.Button
  
      $btn.Text = "RoboCopy"
  
      #register click event   
      $btn.add_click({Add_click})
  
      $mainForm.Controls.Add($btn)
  
      $mainForm.ShowDialog()
  }
  
  #click event
  function Add_click() {
      CopyFolder
  }
  
  function CopyFolder() {
      $sourseFolder = "C:\tmp\tmp"
      $targetFolder = "C:\tmp\tmp2"
  
      $Logfile = "c:\tmp\a.log"
  
      robocopy $sourseFolder $targetFolder /tee /log:$Logfile
  }
  
  function ReadMode() {
      Write-Host Mode [1 for GUI mode]
  
      $mode = Read-Host
  
      if ($mode -eq 1) {
          createdMainForm
      } else {
          CopyFolder
      }
  }
  
  ReadMode
  </code></pre>
  
  <p>I want to capture the <code>robocopy</code> progress in a log file as well as in the console.</p>
  
  <p>However only the log file capture the output, while the console "hangs" until end.</p>
  
  <p>I found that is works smoothly when PowerShell does not display form, but simply runs the command.
  The script works in two modes. enter 1 for "form mode" anything else for console mode, where the log actually written to console and file.</p>
  
  <p>How can I use the form, and display the progress in the console?</p>