Ale Tiro Ale Tiro - 3 months ago 12
PowerShell Question

Send files over PSSession

I just burned a couple of hours searching for a solution to send files over an active PSSession. And the result is nada, niente. I'm trying to invoke a command on a remote computer over an active session, which should copy something from a network storage. So, basically this is it:

icm -Session $s {
Copy-Item $networkLocation $PCLocation }


Because of the "second hop" problem, I can't do that directly, and because I'm running win server 2003 I cant enable CredSSP. I could first copy the files to my computer and then send/push them to the remote machine, but how? I tried PModem, but as I saw it can only pull data and not push.

Any help is appreaciated.

Answer

If it was a small file, you could send the contents of the file and the filename as parameters.

$f="the filename"
$c=Get-Content $f
invoke-command -session $s -script {param($filename,$contents) `
     set-content -path $filename -value $contents} -argumentlist $f,$c

If the file is too long to fit in whatever the limits for the session are, you could read the file in as chunks, and use a similar technique to append them together in the target location