Author Posts

October 13, 2017 at 3:54 pm

I have a scenario I'm trying to work out in my mind and I'm struggling to find a way to make it work using PowerShell and I'm not sure I have all the pieces in my mind. I want to send a command to another computer and have it retrieve files from a different computer. So something like this:

A ↦ B ↔ C

Computer A sends the command/code/session/job and all necessary information to Computer B.

Ideally, Computer A disconnects and isn't necessary for any further part and shouldn't be involved in the file transfer.

Computer B reaches out to Computer C and retrieves the files specified by any method.

I'm really not sure where to concentrate my thoughts on this. I'd like to do this with a PSSession but it also seems like its possible to do this as a job but I'm not familiar with jobs and only partially familiar with PSSessions.

What are some of the prerequesites I need to make a script like this work and what do you think is the best way to do this?

I am running this from Windows 10 and PowerShell v5.1

Thank You

October 13, 2017 at 4:26 pm

Do you know about copy-item and -fromsession and -tosession options?

October 13, 2017 at 4:30 pm


1 way would be just to have a script on computer B that does everything it requires. You then just execute the script using

invoke-command -ComputerName 'Computer B' -filepath C:\TheScript.ps1

from Computer A?

October 13, 2017 at 8:54 pm

Hey Tommy,

I'd like for the process to pass on the variables I pick (computernames and usernames, etc). Any clue how to pass that easily?

October 16, 2017 at 8:53 am

Hello, maybe this can help,

New-PSDrive -name "destination" -PSProvider FileSystem -Root "\\$computer\..." -Credential $cred
Copy-Item '\\$source\...' -Destination "destination:\..." -Recurse
Remove-PSDrive -name "destination"