title: How to convert $args to a string and execute?
body: <p>I'd like to pass all arguments that were given to the script and execute.</p>
  
  <p>For example, given <code>execute.ps1</code> script:</p>
  
  <pre><code>Invoke-Expression $($args[0])
  </code></pre>
  
  <p>I can run:</p>
  
  <pre><code>.\execute.ps1 hostname
  myhostname
  </code></pre>
  
  <p>Same with two parameters with this script:</p>
  
  <pre><code>Invoke-Expression "$($args[0]) $($args[1])"
  </code></pre>
  
  <p>and executing it by:</p>
  
  <pre><code>.\execute.ps1 echo foo
  foo
  </code></pre>
  
  <p><strong>How I can make the script universal to support unknown number of arguments?</strong></p>
  
  <p>For example:</p>
  
  <pre><code>.\execute.ps1 echo foo bar buzz ...
  </code></pre>
  
  <hr>
  
  <p>I've tried the following combinations which failed:</p>
  
  <pre><code>Invoke-Expression $args
  </code></pre>
  
  <blockquote>
    <p>Invoke-Expression : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Command'. Specified method is not supported.</p>
  </blockquote>
  
  <hr>
  
  <pre><code>Invoke-Expression [system.String]::Join(" ", $args)
  </code></pre>
  
  <blockquote>
    <p>Invoke-Expression : A positional parameter cannot be found that accepts argument 'System.Object[]'.</p>
  </blockquote>
  
  <hr>
  
  <pre><code>Invoke-Expression $args.split(" ")
  </code></pre>
  
  <blockquote>
    <p>Invoke-Expression : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Command'. Specified method is not supported. </p>
  </blockquote>
  
  <hr>
  
  <pre><code>Invoke-Expression [String] $args
  </code></pre>
  
  <blockquote>
    <p>Invoke-Expression : A positional parameter cannot be found that accepts argument 'System.Object[]'.</p>
  </blockquote>