Param basics

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
    Posts
  • #5809

    by BustedFlush at 2013-04-16 07:13:30

    I read Don's post on param here:
    http://technet.microsoft.com/en-us/maga ... 54301.aspx
    but I'm still very confused. I tried this; it doesn't work. Why not?

    Param(
    [string]$foo,
    [string]$bar
    )

    Write-host $foo, $bar

    PS C:\users\BustedFlush> .\foobar -foo big -bar fish

    At C:\users\BustedFlush\foobar.ps1:2 char:5
    + $foo
    + ~
    Missing ')' in function parameter list.
    At C:\users\BustedFlush\foobar.ps1:4 char:1
    + )
    + ~
    Unexpected token ')' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEndParenthesisInFunctionParameterList

    by JeffH at 2013-04-16 07:20:11

    Is that the complete script?

    by BustedFlush at 2013-04-16 07:23:09

    Yes.

    by JeffH at 2013-04-16 07:29:08

    I had no error. PowerShell seems to think you don't have the closing ). You might open your file in Notepad and look for any weird control characters. Or delete the ) and add it back.

    by BustedFlush at 2013-04-16 07:36:37

    Well, that's weird. It looked exactly the same in notepad, but when I pasted it back in it worked fine.

    OK, cool. Thanks!

You must be logged in to reply to this topic.