Why does pwsh pipe by property even when the property is absent

How does pwsh handle pipeline value by property name for item cmdlet? For example, Get-ChildItem -File | Remove-Item works but Remove-Item only accepts Path or LiteralPath by property while [FileInfo] does not have any of these candidates, why does it still work? Is it specific to item cmdlets? because I can’t reproduce it in my custom function with Path parameter

Have you tried Trace-Command?

Trace-Command -Name ParameterBinding -Expression {Get-ChildItem -File | Remove-Item} -PSHost
3 Likes

The fileinfo objects get converted to string which becomes the fullpath of the file object and this gets mapped (byvalue) to Path which is positionally 0 for Remove-item

1 Like

Cool, didn’t know that feature. It seems pwsh implicitly binds PSPath to LiteralPath, while PSPath is an alias for LiteralPath in Remove-Item which I didn’t notice, so everythign makes sense.

DEBUG: 2025-07-24 04:40:12.2812 ParameterBinding Information: 0 :         Parameter [LiteralPath] PIPELINE INPUT ValueFromPipelineByPropertyName NO COERCION
DEBUG: 2025-07-24 04:40:12.2813 ParameterBinding Information: 0 :         BIND arg [Microsoft.PowerShell.Core\FileSystem::/home/sharpchen/projects/foo/Program.fs] to parameter [LiteralPath]
DEBUG: 2025-07-24 04:40:12.2813 ParameterBinding Information: 0 :             Binding collection parameter LiteralPath: argument type [String], parameter type [System.String[]], collection type Array, element type [System.String], no coerceElementType
DEBUG: 2025-07-24 04:40:12.2814 ParameterBinding Information: 0 :             Creating array with element type [System.String] and 1 elements
DEBUG: 2025-07-24 04:40:12.2815 ParameterBinding Information: 0 :             Argument type String is not IList, treating this as scalar
DEBUG: 2025-07-24 04:40:12.2818 ParameterBinding Information: 0 :             Adding scalar element of type String to array position 0
DEBUG: 2025-07-24 04:40:12.2823 ParameterBinding Information: 0 :             BIND arg [System.String[]] to param [LiteralPath] SUCCESSFUL

Funny … you both came to different conclusions seeing actually the same output … :wink: :winking_face_with_tongue: :face_blowing_a_kiss:

I believe I was wrong. I didn’t notice PSPath alias on Remove-item

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.