Context:
You can set a result of cmdlets to a variable by Set-Variable.
Problem:
You cannot set a result of cmdlets to a property of object by Set-Variable.
PS > $foo = New-Object PSObject | Select-Object Property PS > Get-ChildItem | Set-Variable foo.Property PS > $foo.Property PS >
Reason:
It seems by design.
Solution:
Intead of using Set-Variable, simply assign value to property.
PS > $foo.Property = (Get-ChildItem) PS > $foo.Property Directory: /home/satob Mode LastWriteTime Length Name ---- ------------- ------ ---- ...