title: Script runs in ISE but not in Powershell
body: <p>I have a <a href="https://gist.github.com/sancarn/95cc024887c829077cfd5cccd47f176d#file-script-ps1" rel="nofollow noreferrer">powershell script</a>. This script runs perfectly fine if I open it in Powershell ISE, however, if I right click on the file and click 'run with powershell' the script throws an error.</p>
  
  <p>Furthermore, I read in previous threads that the following execution pattern solved the issue for some people:</p>
  
  <pre><code>powershell -STA -File script.ps1
  </code></pre>
  
  <p>In this case this didn't solve the issue, however it did allow me to read the error:</p>
  
  <pre><code>At C:\Users\sancarn\AppData\Local\Temp\script.ps1:20 char:20
  +         $parent = [System.Windows.Forms.TreeNode]$global:database.Ite ...
  +                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Unable to find type [System.Windows.Forms.TreeNode].
  At C:\Users\sancarn\AppData\Local\Temp\script.ps1:27 char:36
  + ...          [void]$node.nodes.add([System.Windows.Forms.TreeNode]::new(" ...
  +                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Unable to find type [System.Windows.Forms.TreeNode].
  At C:\Users\sancarn\AppData\Local\Temp\script.ps1:33 char:45
  + ... PSCustomObject]IWDBGetChildren([System.Windows.Forms.TreeNode]$node)  ...
  +                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Unable to find type [System.Windows.Forms.TreeNode].
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
      + FullyQualifiedErrorId : TypeNotFound
  </code></pre>
  
  <p>This having been said, I'm not sure I can really do anything about this error specifically... I already load <code>System.Windows.Forms</code>  and <code>System.Drawing</code>... Does anyone have any idea how to execute this file properly?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Other attempts at trying to fix the issue:</p>
  
  <pre><code>powershell -NoExit -STA -File script.ps1
  powershell -NoExit -STA -File script.ps1 -Scope Global
  </code></pre>
  
  <p><strong>Edit 2</strong></p>
  
  <p>I have also tried adding:</p>
  
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  </code></pre>
  
  <p>To the top of the powershell script. The issue remains unresolved however.</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>Not sure why this is being flagged as a duplicate after</p>
  
  <ol>
  <li>this answer already has a recommended answer and</li>
  <li>the recommended answer demonstrates why this is different.</li>
  </ol>
  
  <p>...</p>