[英]passing parameters from a windows batch script into a powershell script
我有一個Powershell腳本,它使用'quser'命令提取有關登錄到一系列終端服務器上的用戶的數據。
我想在輸出文件中添加時間戳,該時間戳變量是在Windows批處理文件中創建的,然后調用powershell腳本傳遞計算機名和時間戳,但是powershell腳本在函數參數列表中出現“ Missing')'錯誤
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。 其他版本的錯誤顯示可能有所不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.