How to pass data down the pipeline

Hi,

I would like to create one liner where I can (somehow) pass computer name down the pipeline.
This will be useful when I have a list with computers that will return me value.

Example:
“Get-Service -computername localhost” will return
Status Name DisplayName


What I’m aiming is to have one more column:
Computer Status Name DisplayName


Can you advice me, how to get that?
I’ve tied with -pipelinevariable parameter, but didn’t get any success.

That’s difficult in a one-liner, because the object produced by Get-Service doesn’t contain that information. Ergo, it doesn’t exist in the pipeline. You can’t “pass data through a command;” the pipeline can only contain what the most recent command ran.

You can accomplish what you want, but not with a one-liner. Why is a one-liner a fixed goal for you?

Fun challenge. Here’s what I came up with.

Get-Service -computername ((Set-Variable -name "comp" -value "localhost" -PassThru).value) | Select-Object @{Label = 'ComputerName'; Expression = {$comp}}, *

Thank you Curtis (that’s for you > https://beeroverip.org/ ), however I now realize that what I want is not possible as the data do not exist.

I wanted to run is the command bellow:
Get-VirtualSwitch -VMHost (get-content c:\hosts.txt) | where {name -like ‘Cluster1_*’}

It will return only names of the filtered Switch, but not which host have it. So nothing major, but still not something that should deserves to be write in ISE (which will load the vmware snapin/module for a lot of time).

Hey @miroslavvasilev,
While I don’t really think it’s worth typing, the same concept can still be used

get-content 'D:\Temp\computers.txt' | ForEach-Object {Get-Service -ComputerName ((Set-Variable -name "comp" -value $_ -PassThru).value)} | Select-Object @{Label = 'ComputerName'; Expression = {$comp}}, *

Or in your case

get-content 'D:\Temp\computers.txt' | ForEach-Object {Get-VirtualSwitch -VMHost ((Set-Variable -name "vmhost" -value $_ -PassThru).value)} | where {name -like 'Cluster1_*'} | Select-Object @{Label = 'ComputerName'; Expression = {$vmhost}}, *

That would do the job as well, thanks.

without additional variables:

get-content 'D:\Temp\computers.txt' | ForEach-Object { Get-Service -ComputerName $_ | Add-Member -MemberType NoteProperty -Name ComputerName -Value $_ -PassThru }

Ooo, that’s nice @max-kozlov, good job.