Windows Vista Forums

Could not compare "1" to "System.Object[]"
  1. #1


    Jsimpson Guest

    Could not compare "1" to "System.Object[]"

    I have a simple for loop and I am getting a wierd error in PS v2 in
    Windows 7 I am sure I am not doing something right, but I am
    stumped...



    for ($a = 1, $a -le 5, $a++) { write-host $a}

    Gives me:

    Bad argument to operator '-le': Could not compare "1" to "System.Object
    []". Error: "Cannot convert the "System.Object[]
    " value of type "System.Object[]" to type "System.Int32".".
    At C:\scripts\Test-network.ps1:2 char:20
    + for ($a = 1, $a -le <<<< 5, $a++)
    + CategoryInfo : InvalidOperation: ( [],
    RuntimeException
    + FullyQualifiedErrorId : BadOperatorArgument


      My System SpecsSystem Spec

  2. #2


    Jsimpson Guest

    Re: Could not compare "1" to "System.Object[]"

    Duh, semicolons, not comas. *blush*

    On Feb 2, 9:00*am, Jsimpson <jsimpson2...@newsgroup> wrote:

    > I have a simple for loop and I am getting a wierd error in PS v2 in
    > Windows 7 I am sure I am not doing something right, but I am
    > stumped...
    >
    > for ($a = 1, $a -le 5, $a++) { write-host $a}
    >
    > Gives me:
    >
    > Bad argument to operator '-le': Could not compare "1" to "System.Object
    > []". Error: "Cannot convert the "System.Object[]
    > " value of type "System.Object[]" to type "System.Int32".".
    > At C:\scripts\Test-network.ps1:2 char:20
    > + for ($a = 1, $a -le <<<< *5, $a++)
    > * * + CategoryInfo * * * * *: InvalidOperation: ( [],
    > RuntimeException
    > * * + FullyQualifiedErrorId : BadOperatorArgument

      My System SpecsSystem Spec

  3. #3


    Martin Zugec Guest

    Re: Could not compare "1" to "System.Object[]"

    Hehe, happened to me too many times at beginning

    BTW does anyone know reason why For is using ";" instead of ","? Just
    to make it less error-prone in case user wants to use 1,2,3?

    Martin

      My System SpecsSystem Spec

  4. #4


    Tim Munro Guest

    Re: Could not compare "1" to "System.Object[]"

    Rough guess off the top of my head...commas delimit elements of an array,
    semi-colons delimit commands on the same line.

    --

    tim



    "Martin Zugec" <martin.zugec@newsgroup> wrote in message
    news:e7c546e8-8054-46e5-b0d1-63c97692fd90@newsgroup

    > Hehe, happened to me too many times at beginning
    >
    > BTW does anyone know reason why For is using ";" instead of ","? Just
    > to make it less error-prone in case user wants to use 1,2,3?
    >
    > Martin


      My System SpecsSystem Spec

  5. #5


    Martin Zugec Guest

    Re: Could not compare "1" to "System.Object[]"

    That's what I ment also (of course @(1,2,3) would to the trick), my second
    guess would be some C* convention...

    Martin

    "Tim Munro" <Excelsior@newsgroup> wrote in message
    news:u5wnhMNpKHA.2076@newsgroup

    > Rough guess off the top of my head...commas delimit elements of an array,
    > semi-colons delimit commands on the same line.
    >
    > --
    >
    > tim
    >
    >
    >
    > "Martin Zugec" <martin.zugec@newsgroup> wrote in message
    > news:e7c546e8-8054-46e5-b0d1-63c97692fd90@newsgroup

    >> Hehe, happened to me too many times at beginning
    >>
    >> BTW does anyone know reason why For is using ";" instead of ","? Just
    >> to make it less error-prone in case user wants to use 1,2,3?
    >>
    >> Martin
    >
    >

      My System SpecsSystem Spec

Could not compare "1" to "System.Object[]" problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Extensible Authentication Protocol" service gives "The system cannot find the file specified" error Samuel Neff Vista networking & sharing 0 24 Feb 2009
Is there a better method than the default "compare-object" IT Staff PowerShell 1 28 Oct 2008
Vista not wotking with "My Computer" or "Control Panel", "Screen Saver" Platebanger Vista General 6 05 Feb 2008
Error: "Cannot convert "System.Object[]" to "System.Int32"." Shay Levi PowerShell 3 31 Jan 2008
Separate hashtable vs $alist | where-object { "key" = "value" } versus something else? ydroam PowerShell 2 12 Dec 2006