Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active November 11, 2025 02:30
Show Gist options
  • Select an option

  • Save sebastiancarlos/3b6342442a69d0fd97c5c2fc11717eba to your computer and use it in GitHub Desktop.

Select an option

Save sebastiancarlos/3b6342442a69d0fd97c5c2fc11717eba to your computer and use it in GitHub Desktop.
Powershell Sample Function
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