@@ -203,23 +203,104 @@ Function Out-ChildItemColor {
203203}
204204
205205Function Get-ChildItemColor {
206- [CmdletBinding ()]
207- Param (
208- [string ]$Path = " "
209- )
206+ [CmdletBinding (DefaultParameterSetName = ' Items' , HelpUri = ' https://go.microsoft.com/fwlink/?LinkID=2096492' )]
207+ param (
208+ [Parameter (ParameterSetName = ' Items' , Position = 0 , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
209+ [string []]
210+ ${Path} ,
211+
212+ [Parameter (ParameterSetName = ' LiteralItems' , Mandatory = $true , ValueFromPipelineByPropertyName = $true )]
213+ [Alias (' PSPath' , ' LP' )]
214+ [string []]
215+ ${LiteralPath} ,
216+
217+ [Parameter (Position = 1 )]
218+ [string ]
219+ ${Filter} ,
220+
221+ [string []]
222+ ${Include} ,
223+
224+ [string []]
225+ ${Exclude} ,
226+
227+ [Alias (' s' )]
228+ [switch ]
229+ ${Recurse} ,
230+
231+ [uint ]
232+ ${Depth} ,
233+
234+ [switch ]
235+ ${Force} ,
236+
237+ [switch ]
238+ ${Name} )
239+
240+
241+ dynamicparam
242+ {
243+ try {
244+ $targetCmd = $ExecutionContext.InvokeCommand.GetCommand (' Microsoft.PowerShell.Management\Get-ChildItem' , [System.Management.Automation.CommandTypes ]::Cmdlet, $PSBoundParameters )
245+ $dynamicParams = @ ($targetCmd.Parameters.GetEnumerator () | Microsoft.PowerShell.Core\Where-Object { $_.Value.IsDynamic })
246+ if ($dynamicParams.Length -gt 0 )
247+ {
248+ $paramDictionary = [Management.Automation.RuntimeDefinedParameterDictionary ]::new()
249+ foreach ($param in $dynamicParams )
250+ {
251+ $param = $param.Value
252+
253+ if (-not $MyInvocation.MyCommand.Parameters.ContainsKey ($param.Name ))
254+ {
255+ $dynParam = [Management.Automation.RuntimeDefinedParameter ]::new($param.Name , $param.ParameterType , $param.Attributes )
256+ $paramDictionary.Add ($param.Name , $dynParam )
257+ }
258+ }
210259
211- Begin {
212- $Expression = " Get-ChildItem -Path `" $Path `" $Args "
213- $Items = Invoke-Expression $Expression
260+ return $paramDictionary
261+ }
262+ } catch {
263+ throw
214264 }
265+ }
266+
267+ begin
268+ {
269+ try {
270+ $outBuffer = $null
271+ if ($PSBoundParameters.TryGetValue (' OutBuffer' , [ref ]$outBuffer ))
272+ {
273+ $PSBoundParameters [' OutBuffer' ] = 1
274+ }
275+
276+ $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand (' Microsoft.PowerShell.Management\Get-ChildItem' , [System.Management.Automation.CommandTypes ]::Cmdlet)
277+ $scriptCmd = {& $wrappedCmd @PSBoundParameters }
278+
279+ } catch {
280+ throw
281+ }
282+ }
283+
284+ process
285+ {
286+ try {
287+ $items = $scriptCmd.invoke ()
215288
216- Process {
217289 If ($PSCmdlet.MyInvocation.Line -Match ' \|' ) { # pipeline is used
218- $Items
290+ $items
219291 } Else {
220- $Items | Out-ChildItemColor
292+ $items | Out-ChildItemColor
221293 }
294+ } catch {
295+ throw
222296 }
223297}
224298
225- Export-ModuleMember - Function Out-ChildItemColor , ' Get-*'
299+ end
300+ {
301+ try {
302+ } catch {
303+ throw
304+ }
305+ }
306+ }
0 commit comments