PoshCode Archive  Artifact [600540dc16]

Artifact 600540dc168666d3194a7c1a4514361ea94ff3072f38ea8df07bf3a6b825d69d:

  • File Get-ChildItemProxy.ps1 — part of check-in [7333dde4a8] at 2018-06-10 14:23:59 on branch trunk — This is an advanced function that uses a proxy command to add two new switches to get-childitem (user: Andy Schneider size: 3001)

# encoding: ascii
# api: powershell
# title: Get-ChildItemProxy
# description: This is an advanced function that uses a proxy command to add two new switches to get-childitem
# version: 0.1
# type: function
# author: Andy Schneider
# license: CC0
# function: Get-ChildItemProxy
# x-poshcode-id: 785
# x-archived: 2014-04-13T02:39:38
# x-published: 2009-01-04T16:29:00
#
# You can name this function get-childitem and it will overwrite the existing cmdlet. 
# With Proxy Commands, you can mess with the meta data and add/subtract parameters from real cmdlets
# Most of this code was generated with Jeffrey Snover’s new Metaprogramming Module
# http://blogs.msdn.com/powershell/archive/2009/01/04/extending-and-or-modifing-commands-with-proxies.aspx
# http://www.get-powershell.com
#
Function Get-ChildItemProxy {
[CmdletBinding(DefaultParameterSetName='Items', SupportsTransactions=$true)]
param(
    [Parameter(ParameterSetName='Items', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
    [System.String[]]
    ${Path},

    [Parameter(ParameterSetName='LiteralItems', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
    [Alias('PSPath')]
    [System.String[]]
    ${LiteralPath},

    [Parameter(Position=1)]
    [System.String]
    ${Filter},

    [System.String[]]
    ${Include},

    [System.String[]]
    ${Exclude},

    [Switch]
    ${Recurse},

    [Switch]
    ${Force},

    [Switch]
    ${Name},
    
    [Switch]
    ${ContainersOnly},
    
    [Switch]
    ${NoContainersOnly}
    )

begin
{
    try {
        $outBuffer = $null
        if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer) -and $outBuffer -gt 1024)
        {
            $PSBoundParameters['OutBuffer'] = 1024
        }
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet)
        
        if ($ContainersOnly)
        {
            [Void]$PSBoundParameters.Remove("ContainersOnly")
            $scriptCmd = {& $wrappedCmd @PSBoundParameters | Where-Object {$_.PSIsContainer -eq $true}}
            
        } elseif ($NoContainersOnly)
               {
                   [Void]$PSBoundParameters.Remove("NoContainersOnly")
                   $scriptCmd = {& $wrappedCmd @PSBoundParameters | Where-Object {$_.PSIsContainer -eq $false}}
               }    
        {
            $scriptCmd = {& $wrappedCmd @PSBoundParameters }
        }
        

        
        $steppablePipeline = $scriptCmd.GetSteppablePipeline()
        $steppablePipeline.Begin($PSCmdlet)
    } catch {
        throw
    }
}

process
{
    try {
        $steppablePipeline.Process($_)
    } catch {
        throw
    }
}

end
{
    try {
        $steppablePipeline.End()
    } catch {
        throw
    }
}
<#

.ForwardHelpTargetName Get-ChildItem
.ForwardHelpCategory Cmdlet

#>

}