Missing ')' in function parameter list.

Ooker Human 20 Reputation points
2024-07-11T07:47:55.74+00:00

I can run this script fine:

param (
  [switch]$push = $false
)

Why does running this script:

param (
  [switch]$push = $false
  [string]$string
)

yield this error:

Missing ')' in function parameter list.

?

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,328 questions
0 comments No comments
{count} votes

Accepted answer
  1. Q&A Assist
    2024-07-11T07:47:55.7466667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The error message "Missing ')' in function parameter list" is caused by the fact that the second parameter in the script is missing a comma to separate it from the first parameter. In PowerShell, parameters in a function or script must be separated by commas. To fix the error, add a comma after the first parameter like this:

    param (
      [switch]$push = $false,
      [string]$string
    )
    

    This will allow the script to run without error and accept two parameters, a switch parameter named "push" with a default value of $false, and a string parameter named "string".

    References:

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful