Problems with powershell function syntax.

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 3 years, 8 months ago.

  • Author
    Posts
  • #10906
    Profile photo of Timothy Badenach
    Timothy Badenach
    Participant

    Hi I am new to powershell and I am having a problem running a script that I have modified to install software from my usb key

    The USB key is a 64 GB stick partitioned into four drives w:, x:, y: and z:

    I am running this script

    Function Install-Software
    {
    PARAM
    (
    $file = "Z:\scripts\Adobe Photoshop CS6 Extended\SOFTWARE\Set-up.exe",
    $Arguments ='/q CONTENT_DIR="Z:\scripts" DEFAULT_WEBSITE=0 CONTENT_LOCAL=1'
    )

    $Install = Start-Process $File -ArgumentList $Arguments -Wait -PassThru

    If($Install.ExitCode -eq 0){
    Write-Host "Installation was OK" -ForegroundColor GREEN
    }
    Else
    {
    Write-Host "Installation failed $("$Install.ExitCode")" -ForegroundColor RED
    }

    }

    No matter what I do I always get this error:

    PS Z:\Scripts> .\script.ps1
    Missing ')' in function parameter list.
    At Z:\Scripts\Script.ps1:4 char:13
    + $Z: < <<< \scripts\Adobe Photoshop CS6 Extended\SOFTWARE\Set-up.exe + CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Parse Exception + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList PS Z:\Scripts>

    But as you can see there is definately a ) there. I know it is just a simple syntax error but blowed if I can find out what is wrong with this script

    Any help would be great

    Tim

  • #10907
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    It looks fine to me, except for the "smart quotes" that the forum software automatically inserts when you post code outside of a CODE or PRE block. When I replaced all of those with normal single and double quotation marks, the function executed without any errors regarding the param block:

    Function Install-Software
    {
        PARAM
        (
            $file = 'Z:\scripts\Adobe Photoshop CS6 Extended\SOFTWARE\Set-up.exe',
            $Arguments ='/q CONTENT_DIR="Z:\scripts" DEFAULT_WEBSITE=0 CONTENT_LOCAL=1'
        )
    
        $Install = Start-Process $File -ArgumentList $Arguments -Wait -PassThru
    
        If($Install.ExitCode -eq 0){
            Write-Host "Installation was OK" -ForegroundColor GREEN
        }
        Else
        {
            Write-Host "Installation failed $("$Install.ExitCode")" -ForegroundColor RED
        }
    }
    

You must be logged in to reply to this topic.