Help New-item -parameter "Value"
show us -Value <System.Object> could be bind ByPropertyName or ByValue. The question is:
** Is it possible pipe ByPropertyName? **
As ByValue takes precedence over ByPropertyName, I can't find any example to be able to do that pipe. Anything I write to the left is an object, and is bound by ByValue, even if that object has the -Value attribute.
Thank you
Example:
$customObject = [PSCustomObject]@{
Value = "Lorem ipsum"
}
$customObject | New-Item -Name BPN_value.txt
The content of BPN_value.txt is @{Value = "Lorem ipsum"} because $customObject is an object (obviously) and it's binding byValue to the paramete Value of New_Item
No, because as you have already noticed, the parameter type is
System.Objectand since all objects inherit from this class every input from pipeline is bound withValueFromPipelineinstead ofValueFromPipelineByPropertyName.Should the type for this parameter be other than
System.Object?No, because it would conflict with other providers. In example, defining a new function would no longer be possible:
Should the
-Valueparameter be enabled to bind by Property Name?Probably not, because it can never be bound by it.
Is there a workaround?
You could have a ProxyCommand or wrapper function around
New-Itemthat changes the parameter type fromSystem.ObjecttoSystem.String, this way the function would be able to work properly takingValueFromPipelineandValueFromPipelineByPropertyName. You could then store this wrapper in your$PROFILEand have it available for you each time a new session is started.For the reasons stated before, this wrapper would only work targetting the
FileSystemprovider and has been hardcoded forItemType = File.For reference, the definition of the code used above was autogenerated using:
Then it has been slightly modified and simplified for this specific answer.