Get Remotely, Store Locally

by Dec 4, 2009

When you start using PowerShell remotely, you may run into situations like this one:

Invoke-Command -ComputerName remotepc {
Get-Process | Select-Object Name |Export-Csv c:\result.csv

Here, PowerShell gets all processes from "remotepc," selects just the process names and exports them to a csv file. The problem is that the csv file with your results is stored on the remote system. So, how do you get to it?

Stop before you start thinking about complex copy operations. Remote will automatically delivers the information back to you. It is just a matter of where you place the output cmdlet. You should place it outside the remotely executed script block to store the results on your machine:

Invoke-Command -ComputerName remotepc `
{ Get-Process | Select-Object Name } |
Export-Csv c:\result.csv

Twitter This Tip! ReTweet this Tip!