none
Unexpected Token '(' in expression or statement. RRS feed

  • Question

  • I'm trying to retrieve DHCP server names and Leases using this script. But when I execute this section of the script of receive the following error message:

    Pwershell> C:\PowerShell\DHCPLease.ps1


    At C:\PowerShell\DHCPLease.ps1:287 char:25

    +  $line = $AllScopes[$i] (Read-Host " ").Split(",")

    +                         ~

    Unexpected token '(' in expression or statement.

        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

        + FullyQualifiedErrorId : UnexpectedToken

    Here is the part of the script that is failing

    #region Get all Scopes in the Server


    # Run the Command in the Show Scopes var


    $AllScopes=Invoke-Expression$ShowScopes


    # Go over all the Results, start from index 5 and finish in last index -3


    for($i=5;$i-lt$AllScopes.Length-3;$i++)

    {

    # Split the line and get the strings


    $line=$AllScopes[$i](Read-Host" ").Split(",")   -   This is the line I receive the error

    $Scope.Address +=Check-Empty$line[0]


    $Scope.Mask +=Check-Empty$line[1]


    $Scope.State +=Check-Empty$line[2]


    # Line 3 and 4 represent the Name and Comment of the Scope


    # If the name is empty, try taking the comment


    If(Check-Empty$line[3]-eq"-") {

    $Scope.Name +=Check-Empty$line[4]


    }

    else{ $Scope.Name +=Check-Empty$line[3]}

    }

    Tuesday, November 4, 2014 2:50 PM

All replies

  • That "read-host" seems weird, that cmdlet is supposed to be used to read input from a user typing into the console. Try changing this line

    $line = $AllScopes[$i] (Read-Host" ").Split(",")

    to this

    $line = $AllScopes[$i].Split(",")

    DJ Grijalva | MCITP: EMA 2007/2010 SPA 2010 | www.persistentcerebro.com

    Tuesday, November 4, 2014 3:16 PM