Created
September 18, 2018 23:12
-
-
Save IISResetMe/cb653ad0b75975e52c565f798c78ef48 to your computer and use it in GitHub Desktop.
This file contains 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
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