title: How to pass command-line arguments to a PowerShell ps1 file
body: <p>For years, I have used the <code>cmd/DOS/Windows</code> shell and passed command-line arguments to batch files. For example, I have a file, <code>zuzu.bat</code> and in it, I access <code>%1</code>, <code>%2</code>, etc. Now, I want to do the same when I call a <code>PowerShell</code> script <code>when I am in a Cmd.exe shell</code>. I have a script, <code>xuxu.ps1</code> (and I've added PS1 to my PATHEXT variable and associated PS1 files with PowerShell). But no matter what I do, I seem unable to get anything from the <code>$args</code> variable. It always has length 0.</p>
  
  <p>If I am in a <code>PowerShell</code> shell, instead of <code>cmd.exe</code>, it works (of course). But I'm not yet comfortable enough to live in the PowerShell environment full time. I don't want to type <code>powershell.exe -command xuxu.ps1 p1 p2 p3 p4</code>. I want to type <code>xuxu p1 p2 p3 p4</code>. </p>
  
  <p>Is this possible, and if so, how?</p>
  
  <p>The sample I cannot get to work is trivial, foo.ps1:</p>
  
  <pre><code>Write-Host "Num Args:" $args.Length;
  foreach ($arg in $args) {
      Write-Host "Arg: $arg";
  }
  </code></pre>
  
  <p>The results are always like this:</p>
  
  <pre><code>C:\temp&gt; foo
  Num Args: 0
  C:\temp&gt; foo a b c d
  Num Args: 0
  c:\temp&gt;
  </code></pre>