title: calling Invoke-Expression with Parameters in Powershell
body: <p>I've written a powershell module in c# that has a bunch of cmdlets like</p>
  
  <p>Add-VM</p>
  
  <p>The cmdlets reach out to an API and pull data back.</p>
  
  <p>but for the sake of uniformity with the ssh CLI of the product, i've written a function called newtask that accepts 'addvm' as an argument and $args.</p>
  
  <p>for example</p>
  
  <pre><code>newtask addvm -id 12345
  </code></pre>
  
  <p>I then invoke Add-VM and pass $args as a string like so</p>
  
  <pre><code>Invoke-Expression Add-VM $argstr
  </code></pre>
  
  <p>The problem is that Add-VM throws an error that it cannot find a positional parameter that accepts argument System.Object[]</p>
  
  <blockquote>
    <p>A positional parameter cannot be found that accepts argument 'System.Object[]'</p>
  </blockquote>
  
  <p>While I could easily alias 'addvm' to 'Add-VM', i'm trying to maintain uniformity with the ssh CLI so that new users can quickly start utilizing this module.</p>
  
  <p>I figured that sending a string like '-id 12345' would suffice but it's not. Does the pscmdlet expect to receive something else?</p>
  
  <p>Thanks in advance.</p>