July 2018
Beginner
552 pages
13h 18m
English
Decorating a script block with the function keyword and a name is, at first, the only thing that makes a function. Adding your functions to a module will enable you to package them, version them, and ship them as a single unit.
While you can certainly create functions in your code dynamically, it is not recommended. There is no good reason to not create a proper function declaration:
# Using the function PSDrive, create a new function in your codeNew-Item -Path function:\MyFunction -Value {param($Id) Get-Process -Id $Id}MyFunction -id $pid& (Get-Item Function:\MyFunction) -id $pid
Consider the following code. You should be able to immediately spot why using a function might be the best option here:
# The legacy code
Read now
Unlock full access