1

\I have tried everything I can find on the web but I just can't make this work.... Really frustrating. All I want to do is to pass in a file name in the command line to my Powershell script test.ps1.

param([String]$input=$args[0])
$inputpath = 'C:\work\'
$inputfile = $($inputpath + $input+".txt")

I run the script like:

powershell .\test.ps1 "input"

However, the in the error message I print out, I keep getting "cannot find c:\work\.txt". Apparently my command line parameter isn't in there correctly. Can someone please help?

4

2 回答 2

4

尝试更改$Input为其他名称。因为$Input用于管道变量。

参见例如:

http://blogs.technet.com/b/heyscriptingguy/archive/2010/12/31/write-powershell-functions-that-accept-pipelined-input.aspx

于 2013-07-10T16:32:40.393 回答
0

我只是用它来构建路径:

$inputpath = 'C:\work\'
$inputfile = Join-Path $inputpath ($args[0] + ".txt")
于 2013-07-10T16:37:22.237 回答