Author Posts

December 19, 2016 at 12:45 am

Reading the documentation about the Set-ItemProperty cmdlet here, I got a doubt:

In example #3, which ParameterSet is being used by the Set-ItemProperty cmdlet?

Here's the code:

Get-ChildItem weekly.txt  |  Set-ItemProperty -Name IsReadOnly -Value $true

Which ParameterSet is being used?

December 19, 2016 at 7:10 am

Trace-Command -Name ParameterBinding -Expression { Get-ChildItem weekly.txt | Set-ItemProperty -Name IsReadOnly -Value $True } -PSHost

December 19, 2016 at 2:54 pm

DEBUG: ParameterBinding Information: 0 : BIND PIPELINE object to parameters: [Set-ItemProperty]
DEBUG: ParameterBinding Information: 0 : PIPELINE object TYPE = [System.IO.FileInfo]
DEBUG: ParameterBinding Information: 0 : RESTORING pipeline parameter's original values
DEBUG: ParameterBinding Information: 0 : Parameter [Credential] PIPELINE INPUT ValueFromPipelineByPropertyName NO COERCION
DEBUG: ParameterBinding Information: 0 : Parameter [Path] PIPELINE INPUT ValueFromPipelineByPropertyName NO COERCION
DEBUG: ParameterBinding Information: 0 : Parameter [Credential] PIPELINE INPUT ValueFromPipelineByPropertyName NO COERCION
DEBUG: ParameterBinding Information: 0 : Parameter [LiteralPath] PIPELINE INPUT ValueFromPipelineByPropertyName NO COERCION
DEBUG: ParameterBinding Information: 0 : BIND arg [Microsoft.PowerShell.Core\FileSystem::C:\01Servers\error.txt] to parameter [LiteralPath]
DEBUG: ParameterBinding Information: 0 : Binding collection parameter LiteralPath: argument type [String], parameter type [System.String[]], collection type Array, element type [System.Strin
g], no coerceElementType
DEBUG: ParameterBinding Information: 0 : Creating array with element type [System.String] and 1 elements
DEBUG: ParameterBinding Information: 0 : Argument type String is not IList, treating this as scalar
DEBUG: ParameterBinding Information: 0 : Adding scalar element of type String to array position 0
DEBUG: ParameterBinding Information: 0 : BIND arg [System.String[]] to param [LiteralPath] SUCCESSFUL

Looks like it is LiteralPath that is receiving the property from Get-Childitem.

December 19, 2016 at 10:32 pm

@i255d : thanks. Checking the doc, I see LiteralPath PARAMETER has an alias ( PSPath ), which, AFAIR, is added ( along with others properties ) to all PSObject's that contain a path. It would be great if Trace-Command could make this clear in its output, i.e., that the binding occurs due to the alias PSPath.