Ich verwende Powershell 5, wenn diese relevant istPowershell: Pipeline-Objekte in Pipeline-Objekte
Wenn eine Eigenschaft auf das aktuelle Element in einer Pipeline ergänzt:
Ich kann nicht auf beziehen $ _bis habe ich es in eine andere Pipeline gefüttert. Warum?
# make some objects to pass around
$test = (0..3) | %{[pscustomobject]@{key1="v$_.1";key2="v$_.2"} }
# GM = TypeName: System.Management.Automation.PSCustomObject
# trying to use the current pipeline object
$test | Add-Member @{key3=$_.key1}
$test | ft *
key1 key2 key3
---- ---- ----
v0.1 v0.2
v1.1 v1.2
v2.1 v2.2
v3.1 v3.2
# try again, this time taking the current pipeline object...
#... and then putting it into another identical looking pipeline
$test | %{ $_ | Add-Member @{key4=$_.key1} }
$test | ft *
key1 key2 key3 key4
---- ---- ---- ----
v0.1 v0.2 v0.1
v1.1 v1.2 v1.1
v2.1 v2.2 v2.1
v3.1 v3.2 v3.1
Ich vermute, es könnte sein, dass die erste automatisch etwas was impliziert, und ich habe nicht die unsichtbare/implizierte Funktion weitergeben $ PSItem erzählt.
Alle Argumente, die vor dem Start der Pipeline ausgewertet wurden. '[pscustobject] @ {key1 = 'etwas anderes'} | % {$ test | Add-Mitglied @ {key3 = $ _. Key1}} '. – PetSerAl