https://github.com/startautomating/wherefor
Wherefore Art Thou PowerShell? Multiple Object Pipelines
https://github.com/startautomating/wherefor
Last synced: 5 months ago
JSON representation
Wherefore Art Thou PowerShell? Multiple Object Pipelines
- Host: GitHub
- URL: https://github.com/startautomating/wherefor
- Owner: StartAutomating
- License: mit
- Created: 2024-12-07T22:23:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-08T22:18:13.000Z (about 1 year ago)
- Last Synced: 2025-08-17T00:56:21.895Z (5 months ago)
- Language: PowerShell
- Size: 79.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# WhereFor
Wherefore Art Thou PowerShell? Multiple Object Pipelines
## What Is WhereFor?
WhereFor is a small PowerShell module that combines Where-Object and Foreach-Object into a single useful command, `Get-WhereFor`.
Using WhereFor, it's simple and straightforward to check for multiple conditions in a single pipeline, thus avoiding repeated passes over the same data.
### Installing and Importing
You can install WhereFor from the PowerShell Gallery with Install-Module:
~~~PowerShell
Install-Module WhereFor -Scope CurrentUser
~~~
After installation, you can import the module by name:
~~~PowerShell
Import-Module WhereFor
~~~
### Examples
#### Get-WhereFor Example 1
~~~PowerShell
1..3 | ?% @{
{$_ % 2} = {"$_ is odd"}
{-not ($_ %2)}={"$_ is even"}
}
~~~
#### Get-WhereFor Example 2
~~~PowerShell
Get-Process |
WhereFor @{
{ $_.Handles -gt 1kb } = { "$($_.Name) [ $($_.Id) ] has $($_.handles) open handles " }
{ $_.WorkingSet -gt 1gb } = { "$($_.Name) [ $($_.Id) ] is using $($_.WorkingSet) of memory" }
}
~~~
#### Get-WhereFor Example 3
~~~PowerShell
"the quick brown fox jumped over the lazy dog" -split '\s' |
Get-WhereFor ([Ordered]@{
{ $_ } =
{ "Word: $_"; "Length: $($_.Length)" }
{ $_ -match '[aeiou]' } =
{ "Vowels: $($_.ToCharArray() -match '[aeiou]')" }
{ $_ -match '[^aeiou]' } =
{ "Consonant: $($_.ToCharArray() -match '[^aeiou]')" }
})
~~~
### How It Works
PowerShell is full of interesting features that are not broadly understood.
WhereFor is built using one of these features, the [steppable pipeline](https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.steppablepipeline?view=powershellsdk-7.4.0&wt.mc_id=MVP_321542).
SteppablePipelines allow you to run one more object pipelines step by step.
WhereFor works in a very simple way. You provide one or more dictionaries or hashtables to WhereFor, and it creates a steppable pipeline for each condition and value.
If the condition returned a value, the action is run.