将参数从Windows批处理脚本传递到PowerShell脚本

我有一个powershell脚本,它使用“quser”命令来提取有关用户login到一系列terminal服务器的数据。

我想添加一个时间戳到输出文件,这个时间戳variables创build在一个Windowsbatch file,然后调用PowerShell脚本传递计算机名和时间戳,但PowerShell脚本错误与'失踪')'在函数参数列表'

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

如果我删除我添加的行(在上面的代码中标记),脚本运行良好

您需要在参数之间添加逗号:

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

另外,除非你想要多个时间戳,你可能只是希望它是一个字符串而不是一个字符串数组(如[string]$timestamp )。

我得到的错误信息看起来像这样(除了它是红色的)。 第一个错误点在本地主机线的末尾,然后有一个什么时候似乎是一个虚假的连锁错误)

 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 

我在这里使用Powershell 3。 其他版本可能会显示不同的错误。