PowerShell – Error – “Missing closing ‘)’ in expression” – Param // Set-StrictMode


Getting an error when I try to run a PowerShell script.

The PowerScript accepts parameters and thus it includes the Param Statement.

It also enforces a Strict Mode; principally it requires that all variables should be explicitly declared.

Error Message

Here is the error message:

Missing closing ')' in expression.
+     <<<< [alias("F")]
    + CategoryInfo          : ParserError: (CloseParenToken:TokenId) [], ParseException
    + FullyQualifiedErrorId : MissingEndParenthesisInExpression



Original Code

Here is the original code:

Set-StrictMode -Version 1
   [Parameter(Mandatory=$true, position=0, HelpMessage="Filename input")]

Revised Code

	[Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]

Set-StrictMode -Version 1


  1. The very first line needs to be the Function argument definition
    • Param
  2. And, the “Set-StrictMode -Version #” can then follow
    • Set-StrictMode -Version 1
    • Or  “Set-StrictMode -Version 2

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s