title: Dynamically generate command-line command, then invoke using powershell
body: <p>Using powershell, you can use the '&amp;' character to run another application and pass in parameters.</p>
  
  <p>A simple example.</p>
  
  <pre><code>$notepad = 'notepad'
  $fileName = 'HelloWorld.txt'
  
  # This will open HelloWorld.txt
  &amp; $notepad $fileName   
  </code></pre>
  
  <p>This is good. But what if I want to use business logic to dynamically generate a command string? Using the same simple example:</p>
  
  <pre><code>$commandString = @('notepad', 'HelloWorld.txt') -join ' ';
  &amp; $commandString
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>The term 'notepad HelloWorld.txt' is
    not recognized as the name of a
    cmdlet, function, script file, or
    operable program. Check the spelling
    of the name, or if a path was
    included, verify that the path is
    correct and try again.</p>
  </blockquote>
  
  <p>In my real example I'm trying to dynamically add or remove options to the final command line string. Is there a way I can go about this?</p>