Please feel free to provide feedback or file bugs here.

ValueFromPipeline taking precedence over ValueFromPipelineByPropertyName

When a cmdlet has a -value parameter that accepts pipeline data both ByValue and ByPropertyName it always takes it by value. I have seen this in both Set-Variable and Set-Content using PowerShell v5.

For example, consider the following code:

[PSCustomObject]@{
'Path' = 'C:\Temp\MyFile.txt'
'Value' = 'PowerShell is fun!'
} | Set-Content

The above does create the file C:\Temp\MyFile.txt (assuming the directory path exists), but the content is not what I would expect. What I would expect is that the file contain the text 'PowerShell is fun!' and nothing else. What it instead contains is a hashtable representing the entire object:

@{'Path' = 'C:\Temp\MyFile.txt';'Value' = 'PowerShell is fun!'}

I think a better way of handling this would be to have ValueFromPipelineByPropertyName take precedence over ValueFromPipeline.

3 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Matt ErnstMatt Ernst shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base