title: Using Powershell's Invoke-Command to call a batch file with arguments
body: <p>I want to use Powershell in order to call a batch file on remote machines. This batch file has arguments. Here's what I have so far:</p>
  
  <pre><code>$script = "\\fileshare\script.cmd"
  $server = $args[0]
  $args [string]::join(',',$args[1 .. ($args.count-1)])
  
  Invoke-Command -computername $server {$script + ' ' + $args}
  </code></pre>
  
  <p>After a bit of searching, I found that the Invoke-Command function runs its scriptblock in a whole new process, so you can't put variables in it (they won't get expanded). That's what the -ArgumentList tag is for. So I tried this instead...</p>
  
  <pre><code>Invoke-Command -computername $server {\\fileshare\script.cmd} -ArgumentList "FirstArgument"
  </code></pre>
  
  <p>That didn't work either... my batch script tells me it's not being passed any arguments. I can't find anything that explicitly says so, but it looks like the -ArgumentList parameter only works on Powershell scripts (it won't feed them to a batch script).</p>
  
  <p>Any ideas how I can use Invoke-Command to call a batch file with arguments?</p>