Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ A collection of general-purpose functions for objects, properties, and more.
- [Remove-ParameterDefault](https://github.com/brianary/ModernConveniences/wiki/Remove-ParameterDefault): Removes a value that would have been used for a parameter if none was specified, if one existed.
- [Repair-MarkdownHeaders](https://github.com/brianary/ModernConveniences/wiki/Repair-MarkdownHeaders): Updates markdown content to replace level 1 & 2 ATX headers to Setext headers.
- [Select-CapturesFromMatches](https://github.com/brianary/ModernConveniences/wiki/Select-CapturesFromMatches): Selects named capture group values as note properties from Select-String MatchInfo objects.
- [Select-Each](https://github.com/brianary/ModernConveniences/wiki/Select-Each): Returns each element from a collection for the next process in the pipeline, individually.
- [Select-ScriptCommands](https://github.com/brianary/ModernConveniences/wiki/Select-ScriptCommands): Returns the commands used by the specified script.
- [Set-Clip](https://github.com/brianary/ModernConveniences/wiki/Set-Clip): Sets the contents of the clipboard with formatted HTML support (cross-platform, and more reliably on Linux Wayland).
- [Set-ParameterDefault](https://github.com/brianary/ModernConveniences/wiki/Set-ParameterDefault): Assigns a value to use for the specified cmdlet parameter to use when one is not specified.
Expand Down
33 changes: 33 additions & 0 deletions src/public/Select-Each.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<#
.SYNOPSIS
Returns each element from a collection for the next process in the pipeline, individually.
.INPUTS
Any collection type.
.OUTPUTS
Each item contained in the collection.
.FUNCTIONALITY
Collection
.EXAMPLE
@{A=1;B=2;C=3} |Select-Each |Measure-Object |Select-Object -ExpandProperty Count
3
#>

#Requires -Version 7.3
[CmdletBinding()] Param(
# The collection to return each item from.
[Parameter(ValueFromPipeline=$true)][psobject] $InputObject
)
Process
{
if($InputObject |Get-Member -Type Method -Name GetEnumerator -ErrorAction Ignore) {return $InputObject.GetEnumerator()}
else
{
Write-Warning "Unable to reliably return each item from type '$($null -eq $InputObject ? '(null)' : $InputObject.GetType().FullName)'."
return ($InputObject)
}
}