Operation is not valid due to the current state of the obje

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 4 months ago.

  • Author
  • #5918

    by scottbass at 2012-09-07 22:48:20

    # create table structure
    $dt = New-Object System.Data.DataTable
    [Void]$dt.Columns.Add("Program Name", [string])
    [Void]$dt.Columns.Add("Return Code", [int])

    # add data to the table

    # print table
    $dt | Format-Table "Program Name" -AutoSize

    Gives the error:

    Operation is not valid due to the current state of the object.
    At :line:0 char]

    Any ideas?


    by mjolinor at 2012-09-08 06:47:22

    Running V3 on W7, I cannot reproduce that error.

    by DonJ at 2012-09-08 07:42:39

    I'm going to move this to Kirk's forum... more of an advanced topic, and he's more likely to have worked with this stuff.

    by poshoholic at 2012-09-08 09:38:58

    I get an issue with PowerShell 2 for this script, but not for PowerShell 3. With PowerShell 2, it seems to be tripping up because you are outputting two tables from one script (a bug that is run into quite regularly in PowerShell 2). Do you need to output your table twice? If not, remove the one you don't want and then output one set of results and see if that fixes the issue.

You must be logged in to reply to this topic.