PowerShell: Automating Administrative Tasks
by Michael Shepard, Chendrayan Venkatesan, Sherif Talaat, Brenton J.W. Blawat
Executing and calling functions
As seen in figure in the Comparing scripts and functions section, defining a function involves using the function keyword and surrounding the code you want with a scriptblock. Executing this function statement simply adds the function definition to the current PowerShell session. To subsequently call the function, you use the function name like you would a cmdlet name, and supply parameters and arguments just like you would for a cmdlet or script.
Tip
Storing the MdAndGo function in a file called MdAndGo.ps1 can be confusing because we're using the same name for the two things. You dot-source the ps1 file to load the function into the session, then you can execute this function. Dot-sourcing the file doesn't run the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access