2014-02-27 274 views
1

我有一个powershell脚本,它使用'quser'命令来提取有关用户登录到一系列终端服务器的数据。从windows批处理脚本传递参数到powershell脚本

我想给输出文件添加一个时间戳,这个时间戳变量是在一个windows批处理文件中创建的,然后调用powershell脚本传递计算机名和时间戳,但powershell脚本与'Missing')'错误功能参数表”

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

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

回答

1

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

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在这里。其他版本可能会显示不同的错误。

+0

谢谢:)大量Doh对我来说:( – nyehus

+0

没问题。顺便说一句,错误信息应该显示你本地主机和'〜'在问题出现的地方(即逗号丢失的地方)。你使用ISE来编辑脚本,它在编辑器中显示一个红色的'〜'下划线,错误号是 – Duncan

+0

没有看到 - 这是整个消息 - 'Missing')'在函数参数列表中。 在C:\ ts_users \ GET-LoggedOnUser.ps1:35焦炭:5 + <<<< [字符串] $时间戳 + CategoryInfo:ParserError:(CloseParenToken:TokenId)[],括号 tContainsErrorRecordException + FullyQualifiedErrorId:MissingEndParenthesisInFunctionParameterList ',我想<<<<表明错误的位置是 – nyehus

相关问题