Parameters 如何将一个函数的默认参数设置为PowerShell 2中另一个函数的输出?
在PowerShell 2中,我有一个函数Get CurrentQuarter返回当前季度 我有另一个函数,它接受参数quarter。我希望使用函数Get CurrentQuarter将其默认为当前季度 我试过:Parameters 如何将一个函数的默认参数设置为PowerShell 2中另一个函数的输出?,parameters,powershell-2.0,default-value,Parameters,Powershell 2.0,Default Value,在PowerShell 2中,我有一个函数Get CurrentQuarter返回当前季度 我有另一个函数,它接受参数quarter。我希望使用函数Get CurrentQuarter将其默认为当前季度 我试过: function Test-ParameterByFunction { param( [string]$quarter = Get-CurrentQuarter ) } Test-ParameterByFunction PowerShell报告: PS > .
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
PS>\test.ps1
“=”后缺少表达式。
在.\test.ps1:4字符:23
+[string]$quarter=试试这个:
[string]$quarter = [string](Get-CurrentQuarter)
试试这个:
[string]$quarter = [string](Get-CurrentQuarter)
谢谢,似乎可以了。:-)谢谢,似乎可以了。:-)