Category: 2. PowerShell Functions
-
Examples of Functions
Example1: The following example is a simple function which returns a current date Type the following command in the PowerShell console to get the output of above example: Output: Example2: The following example is a function which accepts one parameter and returns a value on that parameter. Type the following command to get the input…
-
Advanced function
Advanced functions are those functions which can perform operations that are similar to the operations performed with the cmdlets. These functions are used when a user wants to write a function without having to write a compiled cmdlet. The main difference between using a compiled cmdlet and an advanced function is that the compiled cmdlets are…
-
Simple function
The following block describes you how to create the simplest function in a PowerShell: To add the multiple statements to the function, we must use a semicolon to separate the statements or type each statement on a separate line. To use the function, type the name of the function as given in the following block:…
-
Scope of a function
-
Syntax
The following block describes a syntax for a function: The above syntax includes the following terms:
-
PowerShell Functions
When we need to use the same code in more than one script, then we use a PowerShell function. A function is a list of PowerShell statements whose name is assigned by the user. When we execute a function, we type the name of a function. Like the cmdlets, functions can also have parameters. The function parameters can…