title: How to handle command-line arguments in PowerShell
body: <p>What is the "best" way to handle command-line arguments?</p>
  
  <p>It seems like there are several answers on what the "best" way is and as a result I am stuck on how to handle something as simple as:</p>
  
  <pre><code>script.ps1 /n name /d domain
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>script.ps1 /d domain /n name.
  </code></pre>
  
  <p>Is there a plugin that can handle this better? I know I am reinventing the wheel here.</p>
  
  <p>Obviously what I have already isn't pretty and surely isn't the "best", but it works.. and it is UGLY.</p>
  
  <pre><code>for ( $i = 0; $i -lt $args.count; $i++ ) {
      if ($args[ $i ] -eq "/n"){ $strName=$args[ $i+1 ]}
      if ($args[ $i ] -eq "-n"){ $strName=$args[ $i+1 ]}
      if ($args[ $i ] -eq "/d"){ $strDomain=$args[ $i+1 ]}
      if ($args[ $i ] -eq "-d"){ $strDomain=$args[ $i+1 ]}
  }
  Write-Host $strName
  Write-Host $strDomain
  </code></pre>