Fixing Remoting Sender Information

by Sep 23, 2015

If you use Invoke-Command to remotely execute PowerShell code, you may have noticed that PowerShell remoting adds a new PSComputerName property that tells you where the data came from.

This sample would retrieve the list of processes from a machine called dc-01. The PSComputerName property reports the source computer name which is especially useful if you specify more than one computer.

#requires -Version 2
$code = {
  Get-Process
}

Invoke-Command -ScriptBlock $code -ComputerName dc-01

However, if you pipe the results to Out-GridView, the PSComputerName property dissapears.

As a workaround, when you send the results to Select-Object, the PSComputerName property will show up correctly in the grid view Window:

#requires -Version 2
$code = {
  Get-Process |
    Select-Object -Property Name, ID, Handles, CPU
}

Invoke-Command -ScriptBlock $code -ComputerName dc-01 |
  Out-GridView

Twitter This Tip! ReTweet this Tip!