locked
Unexpected token error when executing script RRS feed

  • Question

  • Hello All,

    I'm having issues running a script and I've just included the relevant snippets below..

    Below are variables declared and the assigned values.

    $path = "\\abcdef.eu.domain.com\Reports"
    $mp_address = "server.domain.com"
    $site_code = "PR2"

    The script throws an error a

    $path\ccmsetup.exe /mp:$mp_address SMSSITECODE=$site_code

    Error output below :

    PS C:\Users\M123\Documents> .\SCCM_Client.ps1
    At C:\Users\M123\Documents\SCCM_Client.ps1:87 char:7
    +     $path\ccmsetup.exe /mp:$mp_address SMSSITECODE=$site_code
    +          ~~~~~~~~~~~~~
    Unexpected token '\ccmsetup.exe' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : UnexpectedToken

    Any advice please?

    Full script is available at the below location

    https://gallery.technet.microsoft.com/SCCM-Client-Health-Check-7a17d672#content

    Thank You.

    SAMUEL


    SamSV

    Tuesday, June 9, 2020 3:56 PM

Answers

  • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1

    Call operator &

    Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings or script blocks. The call operator executes in a child scope. For more about scopes, see about_scopes.

    $path = "\\abcdef.eu.domain.com\Reports"
    $mp_address = "server.domain.com"
    $site_code = "PR2" 
    
    
    & $path\ccmsetup.exe /mp:$mp_address SMSSITECODE=$site_code
    


    • Marked as answer by SamSV Monday, June 15, 2020 10:19 AM
    Wednesday, June 10, 2020 1:29 AM
  • I'm pretty sure that won't work. This should:

       $RunThis = "$path\ccmsetup.exe"
       & $RunThis etc.

    However, the script author should be informed of this. Others have reported the same error and the author says that a new script was uploaded (in February 2020), but the error's still there.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by SamSV Monday, June 15, 2020 10:21 AM
    Wednesday, June 10, 2020 1:56 AM

All replies

  • Contact the author of the script and have them resolve their problem.

    The variable $p is not being combined with the executable name in the way the author thinks it is.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Tuesday, June 9, 2020 6:32 PM
  • https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1

    Call operator &

    Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings or script blocks. The call operator executes in a child scope. For more about scopes, see about_scopes.

    $path = "\\abcdef.eu.domain.com\Reports"
    $mp_address = "server.domain.com"
    $site_code = "PR2" 
    
    
    & $path\ccmsetup.exe /mp:$mp_address SMSSITECODE=$site_code
    


    • Marked as answer by SamSV Monday, June 15, 2020 10:19 AM
    Wednesday, June 10, 2020 1:29 AM
  • I'm pretty sure that won't work. This should:

       $RunThis = "$path\ccmsetup.exe"
       & $RunThis etc.

    However, the script author should be informed of this. Others have reported the same error and the author says that a new script was uploaded (in February 2020), but the error's still there.


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Marked as answer by SamSV Monday, June 15, 2020 10:21 AM
    Wednesday, June 10, 2020 1:56 AM
  • Thank You very much. That did the job.

    SamSV

    Monday, June 15, 2020 10:20 AM
  • Thank You Rich. The Q&A section of that article doesn't give me an option to provide feedback to the author. 

    SamSV

    Monday, June 15, 2020 10:21 AM