title: How do I provide param attributes for a script in PowerShell?
body: <p>I have this script that can be called in two ways:</p>
  
  <pre><code>MyScript -foo path\to\folder
  </code></pre>
  
  <p>or</p>
  
  <pre><code>MyScript -bar path\to\folder
  </code></pre>
  
  <p>(That is, I can either pass a switch plus a folder or a string argument plus a folder.)</p>
  
  <p>I have tried to put <a href="http://technet.microsoft.com/en-us/library/hh847743" rel="nofollow noreferrer">parameter declarations</a> into my script  as to reflect that syntax:</p>
  
  <pre><code>param(
    [parameter(Mandatory=$false)] [switch]$foo,
    [parameter(Mandatory=$false)] [String]$bar,
    [parameter(Mandatory=$true)]  [System.IO.FileInfo]$path
  )
  </code></pre>
  
  <p>But then I have to pass <code>path</code> explicitly to invoke the script:</p>
  
  <pre><code>MyScript -l -path path\to\folder
  </code></pre>
  
  <p>So (how) can I do that making both <code>bar</code> and <code>path</code> positional parameters?</p>
  
  <p><em>Note</em>: If I have picked an extraordinarily stupid syntax for invoking the script, I can still change it.</p>