Function Script:NameofFunction()

This topic contains 2 replies, has 2 voices, and was last updated by  Marc Savignac 2 years, 1 month ago.

  • Author
  • #37643

    Marc Savignac


    I'm reading Step by Step Windows Powershell 3rd edition. At page 187 this function is written:

    Function Script:ConvertToMeters($feet)
    "$feet feet equals $($feet*.31) meters"
    } # end ConvertToMeters

    What is the purpose of Script: before the name of the function?

  • #37646

    Don Jones

    It's scoping the function to the script that it's in. It's actually a really unusual practice – I'm not sure I've seen anyone do that. You might ask Ed (the author) why he chose to do that. Overall it's kind of chock-full of less-than-good practices – the name doesn't follow naming conventions, the parameter declaration is the truncated kind, and it's outputting text rather than a value. I'm not sure what the context was within the book, but it's not how I'd normally expect a PowerShell function to be written.

  • #37663

    Marc Savignac

    Thank you for your reply. I noticed the difference from the other functions and I was curious of what it does.

    P.S Powershell in a month of lunches is a very good book 🙂

You must be logged in to reply to this topic.