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