Copy a file from local machine to srv...(Server) with the powershell script

Sivaguru Sekar 21 Reputation points
2022-12-06T16:57:37.107+00:00

Hi, i need to copy a file from my local machine to server (this server haven't internet connection).

I connected to that server using RDP from my local machine

I need run script on server using powershell, the script should copy a file from my local machine,and i try some scripts but it doesn't work.

It is possible to do this?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Ashish Raj 96 Reputation points
    2022-12-06T17:36:31.187+00:00

    Yes possible using WinRM. You first have to make sure that target server does WinRM enabled. More details here in official doc about WinRM

    Once you have winrm enabled, you need to make sure that you can create session

    $session = New-PSSession –ComputerName TARGETSERVER  
    

    Once you have the session you can copy file from local to target server

    Copy-Item –Path C:\Folder1\filetocopy.txt –Destination 'C:\' –ToSession $session  
    

    References :

    https://learn.microsoft.com/en-us/windows/win32/winrm/portal

    https://www.youtube.com/watch?v=fEJm_PuYTHA&list=PLkSpjPdRpFFJt-H1cgUjh9r_o_wRwhj-N&index=13

    https://www.ipswitch.com/blog/use-powershell-copy-item-cmdlet-transfer-files-winrm

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sivaguru Sekar 21 Reputation points
    2022-12-07T08:10:09.47+00:00

    Thanks for your sources, It helps more.
    I use below script
    from refer your sources. I just add
    Get-credential

    $session = New-PSSession –ComputerName "TARGETSERVER" -credential Get-credential

    Copy-Item –Path C:\Folder1\filetocopy.txt –Destination 'C:\' –ToSession $session

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.