title: powershell windows form browes dialogue
body: <p>Im trying to create a windows form that has a button when clicked will display a folder/file browes window, then the user selects the file/folder and clicks OK and i can then use the selected path as a string for another script.</p>
  
  <p>the problem is that when i run it through PowerGUI (powershell scripting app) it works fine, but when i run through windows powershell  it hangs when loading the browse dialog, anyone seen this before or see what ive done wrong or got an alternative, any help would be appreciated.</p>
  
  <pre><code>cls
  $button = $browse = $form = 0
  [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
  $browse = new-object system.windows.Forms.FolderBrowserDialog
  $browse.RootFolder = [System.Environment+SpecialFolder]'MyComputer'
  $browse.ShowNewFolderButton = $false
  $browse.selectedPath = "C:\"
  $browse.Description = "Choose a directory"
  
  $button1 = New-Object system.Windows.Forms.Button
  $button1.Text = "Choose Directory"
  $button1.Add_Click({$browse.ShowDialog()})
  $button1.left = 20
  $button1.top = 20
  
  $form = New-Object system.windows.forms.Form
  $form.controls.add($button1)
  $form.ShowDialog()
  $form.Dispose()
  
  $browse.SelectedPath
  </code></pre>