Functions in Powershell

User avatar
Site Admin
Posts: 17
Joined: Mon Jun 17, 2019 2:19 pm

Functions in Powershell

Postby hamid Thu Jul 16, 2020 7:01 pm

Hello Club,

Today I'm gonna write a short topic about Powershell Functions, here we go!

A function is a list of PowerShell statements that has a name that you assign. When you run a function, you type the function name. The statements in the list run as if you had typed them at the command prompt.

Code: Select all

function Get-PowerShellProcess { Get-Process PowerShell }
A function can also be as complex as a cmdlet or an application program.

Like cmdlets, functions can have parameters. The parameters can be named, positional, switch, or dynamic parameters. Function parameters can be read from the command line or from the pipeline.

Functions can return values that can be displayed, assigned to variables, or passed to other functions or cmdlets. You can also specify a return value using the return keyword. The return keyword does not affect or suppress other output returned from your function. However, the return keyword exits the function at that line. For more information, see about_Return.

The function's statement list can contain different types of statement lists with the keywords Begin, Process, and End. These statement lists handle input from the pipeline differently.

A filter is a special kind of function that uses the Filter keyword.

Source: Microsoft Docs ... 20program.
Microsoft MVP: Cloud and Datacenter Management

Return to “PowerShell Learning”

Who is online

Users browsing this forum: No registered users and 1 guest