Get-ChildItemProxy by Andy Schneider 4 years ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/785"></script>download | new post
This is an advanced function that uses a proxy command to add two new switches to get-childitem
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
- #>
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository