Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Created September 18, 2018 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/cb653ad0b75975e52c565f798c78ef48 to your computer and use it in GitHub Desktop.
Save IISResetMe/cb653ad0b75975e52c565f798c78ef48 to your computer and use it in GitHub Desktop.
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