Function Script:NameofFunction()

Welcome Forums General PowerShell Q&A Function Script:NameofFunction()

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 years, 9 months ago.

  • Author
    Posts
  • #37643

    Participant
    Points: 0
    Rank: Member

    Hi,

    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

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 0
    Rank: Member

    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 🙂

The topic ‘Function Script:NameofFunction()’ is closed to new replies.