title: Powershell dot source GUI script and return value when button clicked
body: <p>I am dot sourcing a script which builds a GUI form. </p>
  
  <p>The user puts a value in a text box, some input validation happens and then if it passes the user can click a button: The Apply button. (e.g to save the value) </p>
  
  <p>So I want that value returned to my script1 as below: </p>
  
  <p>Any recommendations for a neat way to do this?</p>
  
  <pre><code>#Script1.ps1
  . ($PSScriptRoot + "\GUIForm.ps1"
  InitialiseForm
  
  #When the Ok button is pressed in the GuiForm.ps1 script. 
  #Store value to here to parse elsewhere
  </code></pre>
  
  <pre><code>#GUIForm.ps1
  $TheTextIWantFromTextBox = New-Object system.Windows.Forms.TextBox
  $OkButton.Add_Click({SubmitTextBox})
  
  Function SubmitTextBox()
  {
      $Form.close()
      return $TheTextIWantFromTextBox.Text
  }
  
  Function InitialiseForm()
  {
      [void]$Form.ShowDialog()
  }
  </code></pre>
  
  <p>Note: I have omitted all the code that creates the form etc...If this is relevant I will update!</p>