title: Powershell v2 dynamic command through string arrays
body: <p>I'm trying to build a small GUI tool to weigh folder and file sizes on a mapped network drive.
  The UI has preset checkboxes/radiobuttons that add or remove pipes in the final script to be executed</p>
  
  <p>The 'run' button executes the variable $fullquery</p>
  
  <pre><code>$fullQuery = $querycmd + $querypath + $setrecurse + $query + $querysuffix
  </code></pre>
  
  <p>This should produce the final string;</p>
  
  <p><code>gci g:\foo\bar\ -recurse | where-object {$_.Extension -eq ".psd"} | select -property name, length</code></p>
  
  <p>Each section being stored in the below variables, and the master $fullQuery variable concatenating them into one string to execute;</p>
  
  <p><code>$querycommand</code> # which is; gci</p>
  
  <p><code>$querypath</code> # Which is a set of concatenated string variables</p>
  
  <p><code>$setrecurse</code> # adding (or not) the -recurse flag</p>
  
  <p><code>$query</code> # is the array where the meat of the query goes into; where-object commands (mainly extensions), 
  Each UI element has its own code in string "| where-object {$_.Extension -eq ".psd"} " Enabling a checkbox adds that string onto the $query array.</p>
  
  <p><code>$querysuffix</code> # Is the filter to bring back file/folder sizes and names in pipeable format for display.</p>
  
  <p>I know there's a lot more that needs to be added to that to actually get useful/usable information out and so on, but I've stumbled at being able to get it to give me any information at all so far. Right now it's not producing any errors (or any message) at all so I've got nothing I can paste in.</p>
  
  <p>I've tried numerous ways of performing the execution of $fullquery when the UI button is pushed, but nothing has worked;</p>
  
  <p>I've tried storing $query as a hashtable/array, I've tried executing $fullquery as an array, tried both at the same time.</p>
  
  <p>I've looked at Tome Tanasovski's <a href="https://powertoe.wordpress.com/2010/02/10/dynamic-code-in-powershell/" rel="nofollow" title="post about dynamic code">https://powertoe.wordpress.com/2010/02/10/dynamic-code-in-powershell/</a> </p>
  
  <p>A lot of dynamic code posts on stackexchange are interested in making the names of variables dynamic/mutatable as opposed to the content of those variables.</p>
  
  <p>I've also seen a lot of posts that involve using Invoke-Command and &amp; to execute something with a single string argument, but my issue is that I want to be able to load up an array with a indeterminable number of pipeline commands (rather than arguments) stored as strings and then execute the whole line as if it were a command.</p>
  
  <p>And I even tried just directly storing the command;   <code>$query = | whereobject {...so on }</code>  but of course powershell won't let you do that, it will only accept it as a string.</p>
  
  <p>Given that I've tried exactly what many other people have found to work, I'm starting to wonder if this is a limitation of Powershell V2?</p>