-
-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
Select-PSFObject can add properties from objects other than the object it is selecting from like e.g. this:
$myObject = @{
Id = "Test"
}
$myOtherObject = @{
Name = "Test"
Path = "C:\Temp\test.txt"
}
$myObject | Select-PSFObject 'Id as Name', 'Path from myOtherObject WHERE Name = Id'I'm wondering if it is also possible to add a property based on a variable? I tried several variations of the following, but never got the expected result.
$myObject = @{
Id = "Test"
}
$myVariable = "C:\Temp\test.txt"
$myObject | Select-PSFObject 'Id as Name', 'Path from myVariable'Asked differently, is it possible to express the following two variations in a more succinct and readable way?
$myObject | Select-PSFObject 'Id as Name', @{Name = "Path"; Expression = { [string]$myVariable } }
# or
$myOtherObject = @{
Path = $myVariable
}
$myObject | Select-PSFObject 'Id as Name', 'Path from myOtherObject'