将参数从windows批处理脚本传递到powershell脚本

将参数从windows批处理脚本传递到powershell脚本,windows,variables,batch-file,powershell,parameters,Windows,Variables,Batch File,Powershell,Parameters,我有一个powershell脚本,它使用'quser'命令提取有关登录到一系列终端服务器的用户的数据 我想向输出文件添加时间戳,此时间戳变量是在windows批处理文件中创建的,该批处理文件随后调用powershell脚本并传递computername和时间戳,但powershell脚本在函数参数列表中出现“Missing”(缺失)错误 param( [CmdletBinding()] [Parameter(ValueFromPipeline=$true, Val

我有一个powershell脚本,它使用'quser'命令提取有关登录到一系列终端服务器的用户的数据

我想向输出文件添加时间戳,此时间戳变量是在windows批处理文件中创建的,该批处理文件随后调用powershell脚本并传递computername和时间戳,但powershell脚本在函数参数列表中出现“Missing”(缺失)错误

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

[string[]$timestamp您需要在参数之间添加逗号:

param(
[CmdletBinding()] 
[Parameter(ValueFromPipeline=$true,
           ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = 'localhost',
[string[]]$timestamp
)
另外,除非您需要多个时间戳,否则您可能只希望它是一个字符串而不是一个字符串数组(因此
[string]$timestamp

我收到的错误消息如下所示(除了它是红色的)。第一个错误指向localhost行的末尾,然后出现了一个连锁反应错误,当时似乎是一个虚假的


我正在使用Powershell 3。其他版本可能会以不同方式显示错误。

没问题。顺便说一句,错误消息应该向您显示带有localhost的行以及问题所在位置下的
~
(即逗号缺失的位置)。或者,如果您使用ISE编辑脚本,它会在编辑器中错误所在的位置显示一条红色的
~
下划线。未看到-这是函数参数列表中的全部消息-“Missing”)。在C:\ts\u users\Get LoggedOnUser.ps1:35 char:5+@nyehus,我已将看到的消息添加到我的答案的末尾。我使用的是Powershell 3.0,因此您可能使用的是旧版本,他们可能会改进错误消息。
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