Functions
One way to wrap your script into something reusable and flexible is by converting it into a function. A function, also called a subroutine in other programming languages, is defined as a named group of statements that perform a specific task.
A PowerShell function does exactly that. It wraps lines of code into a single named construct and does a specific task. You can create simple or advanced PowerShell functions.
Simple functions
The simplest function you can create just requires the function
keyword, the function name, and your code wrapped in curly braces:
#--------------------------------------------------# # simple function skeleton #--------------------------------------------------# function <function name> { #your code here }
Here is an example of a very simple function that gets a list of tables for a specific database:
#---------------------------------------- # simple function definition #---------------------------------------- function Get-Tables { Import...