Hast table trouble

I can’t figure out why I’m getting this error after I iterate through my For Each loop after a period of time.

Cannot convert value “2147483648” to type “System.Int32”. Error: “Value was either too large or too small for an Int32.”
At line:120 char:9

  •     $n = $n + $n
  •     ~~~~~~~~~~~~
    • CategoryInfo : MetadataError: (:slight_smile: [], ArgumentTransformationMetadataException
    • FullyQualifiedErrorId : RuntimeException

      [int]$n = 1
      $rowObjects = @()
      ForEach ($row in $rowData) {
      If ($($row.GetType().Name.ToString()) -eq “DataRow”) {
      $rd = @{RowCount=$n;
      $rowObject = New-Object -TypeName PSObject -Property $rd
      $rowObjects += $rowObject
      $n = $n + $n

$rowObjects | ConvertTo-HTML -head $a -Body $b | Out-File d:\Test.htm

You’re doubling $n each time through the loop, instead of just incrementing it by 1 (and you also declared it as an [int], preventing PowerShell from automatically changing its type to something that can hold a larger number.)

Try changing $n = $n + $n to either $n = $n + 1 , or simply $n++

Gee… don’t know how I missed that. I guess I was in too much of a hast. Thanks for the help!