0

In PowerShell 2 I have a function Get-CurrentQuarter that returns the current quarter.

I have another function that takes the parameter quarter. I'd like it to default to the current quarter using the function Get-CurrentQuarter.

I tried:

function Test-ParameterByFunction
{
  param(
    [string]$quarter = Get-CurrentQuarter
  )
}

Test-ParameterByFunction

PowerShell reported:

PS > .\test.ps1
Missing expression after '='.
At .\test.ps1:4 char:23
+     [string]$quarter = <<<<  Get-CurrentQuarter
    + CategoryInfo          : ParserError: (=:String) [], ParseException
    + FullyQualifiedErrorId : MissingExpressionAfterToken

This would be really handy in cleaning up my code. Is there some syntax I'm missing?

Thanks!

1 Answer 1

5

Try this:

[string]$quarter = [string](Get-CurrentQuarter)
1
  • Thanks, that seems to do it. :-)
    – Josiah
    Sep 15, 2012 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.