Reputation: 5949
According to the documentation Set-Variable
's -Name
and -Value
both support ValueFromPipelineByPropertyName but the following code doesn't seem to work as expected:
[PSCustomObject]@{
name="Test"
value="1234"
} | Set-Variable -Force
$Test
Which results in:
name value
---- -----
Test 1234
If I use a ForEach-Object instead I get what I expected:
[PSCustomObject]@{
name="Test"
value="1234"
} | ForEach-Object {
Set-Variable -Name $_.Name -Value $_.Value -Force
}
$Test
Which results in:
1234
I noticed that -Value
also supports ValueFromPipeline not using the property name, maybe that is related to this behavior.
Am I missing something that is needed for Set-Variable
to accept a values for the parameters -Name
and -Value
from the pipeline by property name?
Upvotes: 1
Views: 50
Reputation: 36297
I created this bug on the PowerShell UserVoice site for this issue.
Upvotes: 1