我想编写一个接受参数并使用函数的powershell脚本。带参数*和*函数的Powershell脚本
我尝试这样做:
param
(
$arg
)
Func $arg;
function Func($arg)
{
Write-Output $arg;
}
,但我得到这个:
The term 'Func' is not recognized as the name
of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At func.ps1:6 char:5
+ Func <<<< $arg;
+ CategoryInfo : ObjectNotFound: (Func:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
很好,我想。我会代替试试这个:
function Func($arg)
{
Write-Output $arg;
}
param
(
$arg
)
Func $arg;
但后来,我得到这个:
The term 'param' is not recognized as the name
of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
At C:\Users\akina\Documents\Work\ADDC\func.ps1:7 char:10
+ param <<<<
+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
就是我要求的可行?或者我的要求不合理?
PowerShell脚本的顺序通常是1)Params,2)函数3)执行函数调用/有序cmdlet。 – 2013-02-15 21:13:29
克里斯托弗兰尼,这是一个有益的总结。如果您已将此作为问题发布,我会投票表决。 – 2013-02-17 03:03:39
如果你的心愿意,你可以投票评论。 :) – 2013-02-19 16:10:16