【发布时间】:2015-01-12 01:57:08
【问题描述】:
我想写一个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) 参数,2) 函数 3) 函数调用/命令 cmdlet 执行。
-
Christopher Ranney,这是一个很有帮助的总结。如果您将此作为问题发布,我会投赞成票。
-
如果您愿意,可以投票支持 cmets。 :)
标签: powershell params