【发布时间】:2012-09-06 19:12:54
【问题描述】:
在 PowerShell 2 中,我有一个返回当前季度的函数 Get-CurrentQuarter。
我有另一个函数接受参数 Quarter。我希望使用 Get-CurrentQuarter 函数将其默认为当前季度。
我试过了:
function Test-ParameterByFunction
{
param(
[string]$quarter = Get-CurrentQuarter
)
}
Test-ParameterByFunction
PowerShell 报告:
PS > .\test.ps1
Missing expression after '='.
At .\test.ps1:4 char:23
+ [string]$quarter = <<<< Get-CurrentQuarter
+ CategoryInfo : ParserError: (=:String) [], ParseException
+ FullyQualifiedErrorId : MissingExpressionAfterToken
这对于清理我的代码非常方便。有没有我遗漏的语法?
谢谢!
【问题讨论】:
标签: parameters powershell-2.0 default-value