1

I have a powershell script which uses 'quser' command to extract data regarding users logged onto a series of terminal servers.

I want to add a timestamp to the output files, this timestamp variable is created in a windows batch file which then calls the powershell script passes the computername and timestamp, but the powershell script is erroring with 'Missing ')' in function parameter list'

    param(
[CmdletBinding()] 
[Parameter(ValueFromPipeline=$true,
           ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = 'localhost'
[string[]]$timestamp <========= this is the line I have added
)

If I remove my added line (marked in the code above), the script runs fine

1 Answer 1

1

You need to add a comma between the parameters:

param(
[CmdletBinding()] 
[Parameter(ValueFromPipeline=$true,
           ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = 'localhost',
[string[]]$timestamp
)

Also unless you want multiple timestamps you probably just want it to be a string rather than a string array (so [string]$timestamp).

The error message I get looks like this (except that it is in red). The first error points at the end of the localhost line then there is a knock-on error for what by that time seems to be a spurious ):

PS C:\>     param(
>> [CmdletBinding()]
>> [Parameter(ValueFromPipeline=$true,
>>            ValueFromPipelineByPropertyName=$true)]
>> [string[]]$ComputerName = 'localhost'
>> [string[]]$timestamp
>> )
>>
At line:5 char:38
+ [string[]]$ComputerName = 'localhost'
+                                      ~
Missing ')' in function parameter list.
At line:7 char:1
+ )
+ ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList

I'm using Powershell 3 here. Other versions may show the error differently.

Sign up to request clarification or add additional context in comments.

3 Comments

No problem. BTW the error message should have shown you the line with localhost and a ~ under where the problem was (i.e. where the comma was missing). Or if you use ISE to edit the script it shows a red ~ underline in the editor where the error is.
didnt see that - this is the whole message - 'Missing ')' in function parameter list. At C:\ts_users\Get-LoggedOnUser.ps1:35 char:5 + <<<< [string]$timestamp + CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Paren tContainsErrorRecordException + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList', I suppose the <<<< was indicating where the error was
@nyehus, I've added the message I see to the end of my answer. I'm using Powershell 3.0 so perhaps you are using an older version and they maybe improved the error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.