Last active
November 11, 2025 02:30
-
-
Save sebastiancarlos/3b6342442a69d0fd97c5c2fc11717eba to your computer and use it in GitHub Desktop.
Powershell Sample Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Sample-Function { | |
| # Turns a regular function into an advanced function, adding common | |
| # parameters like `-Verbose` and `-WhatIf`. | |
| # Note: The `[...]` syntax is an "attribute" in PowerShell. | |
| [CmdletBinding()] | |
| # parameter configuration and typing. | |
| param ( | |
| [Parameter(Mandatory, | |
| # Allows to take input from the pipeline, if present. | |
| ValueFromPipeline, | |
| # Allows to take input from a particular property of the | |
| # piped object, if present. | |
| ValueFromPipelineByPropertyName)] | |
| [string[]]$ComputerName | |
| ) | |
| # A 'process' block is needed when accepting pipeline input. | |
| # Otherwise, you can just inline the logic in the function body. | |
| process { | |
| foreach ($Computer in $ComputerName) { | |
| # ... | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment