0
votes

Please note: security is not an issue at all with this application.

I have a "MachineA" that has a file we will call file.txt. I need to get this file onto a "MachineB". Here's the catch, this needs to be done by remotely sending an Invoke-Command script from MachineB to MachineA to kick back the file.

What I have tried so far: I have setup a shared drive (using net use) on MachineB that MachineA can access. This drive is known as z:\ to MachineA.

I can send this command via Invoke-Command from MachineB to MachineA and it will transfer a file from one directory to another directory within MachineA

xcopy c:\users\administrator\desktop\file.txt c:\file.txt

Now if I send the following command in the same manner from MachineB to MachineA it will complain about not being able to see drive Z.

xcopy c:\users\administrator\desktop\file.txt z:\FilesFromVMs\file.txt

Note: if run the second command directly on MachineA from powershell it will move the file but I need to be able to do this remotely via Invoke-Command

1
Seems me like you're trying to do this backwards. Why use invoke-command at all when you can complete the whole process on MachineB by using map-drive or UNC pointing to MachineA? - James C.
It needs to be an automated repeatable process done directly from MachineB. - IsThisThingOn
Yes, run copy command on MachineB.. something like xcopy \\machineA\C$\users\administrator\desktop\file.txt C:\file.txt will copy file from machineA to machineB. - James C.

1 Answers

-2
votes

If security is not an issue, maybe try using UNC Paths \MachineA\C$\Users...\ instead of relying on mapped drive letters? Perhaps that'll do the trick.