Hast table trouble

Welcome Forums General PowerShell Q&A Hast table trouble

This topic contains 2 replies, has 2 voices, and was last updated by

5 years, 4 months ago.

  • Author
  • #11078

    Points: 0
    Rank: Member

    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: (:) [], 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

  • #11081

    Points: 0
    Rank: Member

    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++

  • #11102

    Points: 0
    Rank: Member

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

The topic ‘Hast table trouble’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort