If I have a script like this:
$searchfor = @("wininit","TeamViewer")
Get-Process $searchfor | % {
Get-nettcpconnection -OwningProcess $_.ID |
select @{Name='Process';Expression={(Get-Process -Id $_.OwningProcess).ProcessName }}
}
how can I access the properties that Get-Process $searchfor returned in my select-object?
You can see, in the select expression, I need to do the get-process a second time, even though I feel like I already passed the information to foreach-object
I know i could use foreach($x in $y) instead of foreach-object but is there any way to get the properties of the outside object, when working with pipes?
Get-NetTcpConnectionto a $Var. do NOT pipe it to theSelect-Objectas that will replace the 1stGet-Processobject with the G-NTC object. at that point you should have both the saved $Var and theGet-Processobject available for use in yourSelect-Objectcalculated properties.