title: Type conversion problem in a PowerShell function
body: <p>I am very new to PowerShell scripting and was experimenting with <code>Function</code>. This is the code I wrote:</p>
  
  <pre><code>Function Add
  {
     $sum = 0;
     for($i = 0; $i -le $args.length; ++$i)
     {
       [int] $num = $args[$i]
       $sum += $num
     }
     Write-Output "Sum is $sum"
  }
  </code></pre>
  
  <p>And I tried to call using <code>Add 1,2,3</code>. However, when I execute I get the following error:</p>
  
  <blockquote>
    <p>Cannot convert the "System.Object[]"
    value of type "System.Object[]" to
    type "System.Int32".</p>
  </blockquote>
  
  <p>Any idea how to fix this?</p>