我想編寫一個接受參數並使用函數的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