Skip to content

Instantly share code, notes, and snippets.

@pkutaj
Created January 20, 2022 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkutaj/0cbed81a4f8a6a55bfa6f5f4968d5d3f to your computer and use it in GitHub Desktop.
Save pkutaj/0cbed81a4f8a6a55bfa6f5f4968d5d3f to your computer and use it in GitHub Desktop.
Exemplary Function Accepting Multiple Inputs from Pipeline in PowerShell
### func1
function query-consul () {
param (
[String[]]$consul_keys,
[String]$queryString,
)
foreach ($consul_key in $consul_keys) {
consul kv get -recurse $consul_key_ |
Select-String $queryString
if ($consul_key.length > 1) { Pause }
}
}
# func2
function print-matches-only {
param([Parameter(Mandatory = $true, ValueFromPipeline = $true)][String[]]$matches)
begin{}
process{
Foreach($match in $matches){return $_.Matches.Value}
}
end{}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment