A script may have a lot of functionality, but not all of it is done through a piece of code. In an excellent script, the independence of each functional code can be guaranteed, ensuring that the script is highly available and maintainable, and that when we improve or subtract functionality, we simply delete the corresponding code block. Typically, a code block refers to a function, calling a function, or executing a different block of code in order to implement a variety of functions.
Let's look at one example:
function Time {Get-Date} <enter>
In this way, we have a new function "time" whose function implementation code is "{get-date}".
Try calling it:
As with programming languages, custom functions can also declare parameters:
function (keyword) functions name (parameter) {code}
For example:
function add ($x,$y)
{
$n = $x + $y
“$x+$y=$n”
}
Run Result: