Last active
January 26, 2021 19:53
-
-
Save B4Art/c8b311a0aad3ff3c6bf15bb8226054c4 to your computer and use it in GitHub Desktop.
Select Noteproperty from a List via TabCompletion
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
<# | |
Skip the outermost records based on a column of a list | |
OR | |
Do the opposit and select the outermost records based on a column of a list | |
Use Tabcompletion to select the column | |
Get-Between -list $a.people -NotePropertyName <tabcomplete> [name or age] | |
Age will give: | |
Get-Between -list $a.people -NotePropertyName age | |
name age | |
---- --- | |
John 30 | |
Marie 31 | |
Ton 40 | |
Jolly 20 | |
Caroline 23 | |
Or the other way arround: | |
Get-Between -list $a.people -NotePropertyName age -XorNotBetween | |
name age | |
---- --- | |
Baby 0 | |
Oldy 99 | |
Or with Name: | |
Get-Between -list $a.people -NotePropertyName name | |
name age | |
---- --- | |
John 30 | |
Marie 31 | |
Jolly 20 | |
Caroline 23 | |
Oldy 99 | |
And the other way arround: | |
Get-Between -list $a.people -NotePropertyName name -XorNotBetween | |
name age | |
---- --- | |
Ton 40 | |
Baby 0 | |
#> | |
function get-Between{ | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position = 0)] | |
[System.Object]$List, | |
[Parameter(Mandatory, Position = 1)] | |
<# | |
#> | |
[ArgumentCompleter({ | |
param($cmdName, $paramName, $wordToComplete, $commandAst, $fakeBoundParameter) | |
if ($obj = $fakeBoundParameter['List']) { | |
@($obj| Get-Member -MemberType NoteProperty).Where( { | |
$_.Name -like "$wordToComplete*" | |
} ).ForEach( { | |
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name) | |
} ) | |
} | |
})] | |
[string] $NotePropertyName, | |
[Parameter(Position = 2)] | |
[switch] $XorNotBetween | |
) | |
Begin { | |
$min = ($List.$NotePropertyName | Measure-Object -Minimum).Minimum | |
$max = ($List.$NotePropertyName | Measure-Object -Maximum).Maximum | |
} Process { | |
If ($XorNotBetween) { | |
Write-Output $List.Where({$_.$NotePropertyName -in ($min, $max)}) | |
} else { | |
Write-Output $List.Where({$_.$NotePropertyName -notin ($min, $max)}) | |
} | |
} End { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment