diff --git a/src/Get-ChildItemColor.psd1 b/src/Get-ChildItemColor.psd1 index a3a2a95..4a33218 100644 --- a/src/Get-ChildItemColor.psd1 +++ b/src/Get-ChildItemColor.psd1 @@ -69,7 +69,7 @@ Description = 'Get-ChildItemColor provides colored versions of Get-ChildItem Cmd # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( 'Get-ChildItemColor', - 'Get-ChildItemColorFormatWide' + 'Get-ChildItemColorFormatWide', 'Out-ChildItemColor' ) diff --git a/src/Get-ChildItemColor.psm1 b/src/Get-ChildItemColor.psm1 index 21b238f..e7a7a77 100644 --- a/src/Get-ChildItemColor.psm1 +++ b/src/Get-ChildItemColor.psm1 @@ -203,23 +203,104 @@ Function Out-ChildItemColor { } Function Get-ChildItemColor { - [CmdletBinding()] - Param( - [string]$Path = "" - ) +[CmdletBinding(DefaultParameterSetName='Items', HelpUri='https://go.microsoft.com/fwlink/?LinkID=2096492')] +param( + [Parameter(ParameterSetName='Items', Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] + [string[]] + ${Path}, + + [Parameter(ParameterSetName='LiteralItems', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [Alias('PSPath','LP')] + [string[]] + ${LiteralPath}, + + [Parameter(Position=1)] + [string] + ${Filter}, + + [string[]] + ${Include}, + + [string[]] + ${Exclude}, + + [Alias('s')] + [switch] + ${Recurse}, + + [uint] + ${Depth}, + + [switch] + ${Force}, + + [switch] + ${Name}) + + +dynamicparam +{ + try { + $targetCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet, $PSBoundParameters) + $dynamicParams = @($targetCmd.Parameters.GetEnumerator() | Microsoft.PowerShell.Core\Where-Object { $_.Value.IsDynamic }) + if ($dynamicParams.Length -gt 0) + { + $paramDictionary = [Management.Automation.RuntimeDefinedParameterDictionary]::new() + foreach ($param in $dynamicParams) + { + $param = $param.Value + + if(-not $MyInvocation.MyCommand.Parameters.ContainsKey($param.Name)) + { + $dynParam = [Management.Automation.RuntimeDefinedParameter]::new($param.Name, $param.ParameterType, $param.Attributes) + $paramDictionary.Add($param.Name, $dynParam) + } + } - Begin { - $Expression = "Get-ChildItem -Path `"$Path`" $Args" - $Items = Invoke-Expression $Expression + return $paramDictionary + } + } catch { + throw } +} + +begin +{ + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Management\Get-ChildItem', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + + } catch { + throw + } +} + +process +{ + try { + $items = $scriptCmd.invoke() - Process { If ($PSCmdlet.MyInvocation.Line -Match '\|') { # pipeline is used - $Items + $items } Else { - $Items | Out-ChildItemColor + $items | Out-ChildItemColor } + } catch { + throw } } -Export-ModuleMember -Function Out-ChildItemColor, 'Get-*' +end +{ + try { + } catch { + throw + } +} +}