Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Select-As
{
[CmdletBinding(DefaultParameterSetName='DefaultParameter', HelpUri='https://go.microsoft.com/fwlink/?LinkID=113387', RemotingCapability='None')]
param(
[Parameter(ValueFromPipeline=$true)]
[psobject]
${InputObject},
[Parameter(Mandatory=$true, Position=0)]
[System.Object[]]
${Property},
[string[]]
${ExcludeProperty},
[switch]
${Unique},
[Parameter(ParameterSetName='DefaultParameter')]
[ValidateRange(0, 2147483647)]
[int]
${Last},
[Parameter(ParameterSetName='DefaultParameter')]
[ValidateRange(0, 2147483647)]
[int]
${First},
[Parameter(ParameterSetName='DefaultParameter')]
[ValidateRange(0, 2147483647)]
[int]
${Skip},
[Parameter(ParameterSetName='SkipLastParameter')]
[ValidateRange(0, 2147483647)]
[int]
${SkipLast},
[Parameter(ParameterSetName='DefaultParameter')]
[switch]
${Wait}
)
begin
{
$PSBoundParameters['Property'] = foreach($Prop in $Property){
if($Prop -is [System.Collections.IDictionary] -and $Prop.Count -eq 1){
@{
Name = "$($Prop.Keys[0])"
Expression = @($Prop.Values)[0]
}
} else {
$Prop
}
}
try {
$outBuffer = $null
if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer))
{
$PSBoundParameters['OutBuffer'] = 1
}
$wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Select-Object', [System.Management.Automation.CommandTypes]::Cmdlet)
$scriptCmd = {& $wrappedCmd @PSBoundParameters }
$steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin)
$steppablePipeline.Begin($PSCmdlet)
} catch {
throw
}
}
process
{
try {
$steppablePipeline.Process($_)
} catch {
throw
}
}
end
{
try {
$steppablePipeline.End()
} catch {
throw
}
}
<#
.ForwardHelpTargetName Microsoft.PowerShell.Utility\Select-Object
.ForwardHelpCategory Cmdlet
#>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment