what is a function powershell
A function is a block of code that has a name and it has a property that it is reusable. Like in other programming language we can create function in powershell as well, it is basically groups a number of program statements into a unit and function is given name to it.ry-Catch-Finally. You can intercept any error in try, catch and finally statements. PowerShell supports try/catch/finally, that should feel familiar to all java, .Net developers. PowerShell Version 1 introduced the trap statement that still works; I prefer try/catch/finally.
Like any scripting language, Windows PowerShell lets you create functions that you can reference within PowerShell statements. A function is basically a named block of code. When you call the function name, the script block within that function runs.You can include any PowerShell statements within the script block, and you can add input parameters so you can use the same function in different situations.Let's look at how to create functions, define input parameters, and work with functions in PowerShell scripts.ou can include any PowerShell statements within the script block, and you can add input parameters so you can use the same function in different situations. Let's look at how to create functions, define input parameters, and work with functions in PowerShell scripts.
1 You can use âhost instead of âcomputername when running the function. 2  This parameter is mandatory. 3  If someone runs the function without providing a computer name, the shell will prompt them to enter one or more. 4  The second parameter, $logname, is a simpler parameter.5  It just accepts a string value. The function name should look like a cmdlet name, starting with one of the commonly used Windows PowerShell verbs like âGetâ and ending with a singular noun. 2  Fill in the comment-based help.