title: Collecting user input with pop up window in Powershell
body: <p>so I am trying to prepare a simple robocopy script. the script will be used by almost 500 users, so I am trying to keep it as simple and as user-friendly as possible.</p>
  
  <p>to collect the information such as source and destination, i wanted to have a pop up window asking users to enter the information. I checked on the other forums and here as well, so far i found several alternatives, unfortunately none of them "does the trick"</p>
  
  <p>Option 1 (my favorite except PowerShell hangs when I use it):</p>
  
  <pre><code>
  Add-Type -AssemblyName Microsoft.VisualBasic
  
  $title = 'Your Current File Shares (Source)'
  $msg   = 'Please enter the EEX file share you want to copy from ( please make sure the format is \\server\share\...) :'
  
  $source = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
  
  Add-Type -AssemblyName Microsoft.VisualBasic
  
  $title = 'Your new drive (Destination)'
  $msg   = 'Please enter to where you want to copy your files (please make sure you choose the full destination) :'
  
  $destination = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
  
  
  
  Robocopy $source $Destination /log:N:\logfile.txt 
  </code></pre>
  
  <p>Option 2 (similar to option just a different way to call VB it seems): replying the first line <em>Add-Type -AssemblyName Microsoft.VisualBasic</em> with <em>[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')</em> , doesn't make it any better . </p>
  
  <p>with both 2 options above PowerShell hangs after the 3rd run. SOmetimes after the first run it hangs. Odd thing is it runs succesfully and runs the robocopy command , but then after it's done it stops responding after a few minutes. Not sure if VB is looping in the background and has to be stopped? </p>
  
  <p>Option 3: </p>
  
  <pre><code>$source = Read-Host 'Enter Your current file share:' -AsSecureString
  $destination = Read-Host 'Enter Your new file share:' -AsSecureString
  </code></pre>
  
  <p>This is simple enough, however you cannot control anything in the box, which is something we can live with, but the main issue is the secure string, so it doesn't allow the user to see what he or she is typing, which would lead to a lot of human errors.</p>
  
  <p>Option 4:</p>
  
  <pre><code>function copy_files {
      param (
          [string]$Copy_from,
          [string]$Copy_to
      )
      [pscustomobject]@{
          copy_from = $Copy_from
          copy_to = $copy_to
      }
  }
  
  $result = Invoke-Expression (Show-Command Copy_files -PassThru )
  
  $result 
  </code></pre>
  
  <p>has a form that is really not desirable , with the "copy" in the middle on the bottom (on the bottom of the form one sees ok / copy / cancel ) which would confuse users causing to hit copy and wait for something to happen (as the purpose is to transfer files…) </p>
  
  <p>another negative thing is that it is very limited in terms what text and title you can use (or at least what I can use as I tried to have spaces but it wouldn't recognize it no matter if put them in quotations or double quotations). But such cosmetic con i can live with.</p>
  
  <p>I cannot add any additional modules so showui for example is unfortunately not an option.</p>
  
  <p>Any ideas on how this can be done? </p>
  
  <p>Thanks in advance</p>