Simple function

The following block describes you how to create the simplest function in a PowerShell:

function <function-name>  

{  

    statement-1  

    statement-2  

    statement-N  

}

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:

  1. Function-name  

Example:

PS C:\> function write-command  

>> {  

>> echo "Windows Operating System"  

>> echo "Linux operating System"  

>> }

Type the following command in the PowerShell console to get the output of the above example:

PS C:\> write-command  

Output:

Windows Operating System
Linux operating System

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *