Working with Functions in Windows PowerShell
- 11/11/2015
- Understanding functions
- Using functions to provide ease of code reuse
- Including functions in the Windows PowerShell environment
- Adding help for functions
- Using two input parameters
- Using a type constraint in a function
- Using more than two input parameters
- Using functions to encapsulate business logic
- Using functions to provide ease of modification
- Understanding filters
- Creating a function: Step-by-step exercises
- Chapter 6 quick reference
Chapter 6 quick reference
To |
Do this |
Create a function |
Use the Function keyword, and provide a name and a script block. |
Reuse a Windows PowerShell function |
Dot-source the fi le containing the function. |
Constrain a data type |
Use a type constraint in brackets and place it in front of the variable or data to be constrained. |
Provide input to a function |
Use the Param keyword and supply variables to hold the input. |
To use a function |
Load the function into memory. |
To store a function |
Place the function in a script file. |
To name a function |
Use Get-Verb to identify an appropriate verb, and use the verb-noun naming convention. |