Function Script:NameofFunction()


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?

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.

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 :slight_smile: