-2

I need a way to copy file from a remote PC to local disk using Powershell v2.0 trying with admin rights of that remote PC.

We can copy a file by means of below cmdlet:

Copy-Item -Path C:\somefile.txt -Destination c:\someotherfile.txt

But my question is how to specify my local PC path as Destination path or the remote PC path as the source path in the above cmdlet? How to specify UNC Path for source or destination paths in above cmdlet so that we can actually copy the file to local PC from the remote one?

Nani
  • 1,148
  • 3
  • 20
  • 35
  • What have you figured out so far? Have you got the source and destination paths? Do you know what command is used to copy files? – vonPryz Jan 16 '18 at 06:20
  • @vonPryz my apologies! I have modified the question. please verify and help me out. Thanks. – Nani Jan 16 '18 at 06:32
  • Look up UNC paths and copy the file via those. No need to enter remote session at all. This question is off-topic in Stack Overflow, Superuser would be better. – vonPryz Jan 16 '18 at 07:03

1 Answers1

1

Save the session object into a variable and then pass it into -FromSession parameter of Copy-Item:

 $session = New-PSSession -ComputerName 192.xx.xx.xx.xx -Credential username
 Copy-Item C:\somefile.txt -Destination C:\someotherfile.txt -FromSession $session

First parameter refers to the remote location, where the second parameter refers to the local one.

For pure file copy operation, you don't really need a session object, but the example above uses session. If you want to enter the session, you can simply run the following afterwards:

Enter-PSSession $session
Mustafa Zengin
  • 2,885
  • 5
  • 21
  • 24
  • Thank you very much for helping me out but mine is Powershell v2.0 and "FromSession" option is not available for "Copy-Item". help me with any other possibility – Nani Jan 18 '18 at 11:28