Share via


Windows server 2016 Core: Copy folder using Powershell

Question

Friday, December 28, 2018 6:53 AM

Hello ,

I am tring to copy folder from my local system(In Lan) to aws Remote server(Windows server 2016 core) over the Internet  using powershell command

$Session = New-PSSession -ComputerName "Server123" -Credential "test\administrator"
Copy-Item "D:\Folder003\ -Destination "C:\Folder003_Copy\ -ToSession $Session -Recurse

Command Reference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-6

However I am getting below error on executing the command:

New-PSSession : [xx.xxx.xxx.xxx] Connecting to remote server xx.xxx.xxx.xxx failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a
firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:12

  • $Session = New-PSSession -ComputerName "xx.xxx.xxx.xxx" -Credential " ...
    +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
        + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed

Could anyone suggest what is missing here ?

All replies (19)

Friday, December 28, 2018 7:27 AM

Read the error message. It is telling you that remoting is not installed/configured.

Test-WsMan  -ComputerName xx.xxx.xxx.xxx -Credential test\administrator

\(ツ)_/


Friday, December 28, 2018 9:56 AM

Hi,

Thanks for your question.

Did you enable windows remoting on the destination computer? (Enable-PSRemoting or winrm quickconfig)

Run PowerShell with the administrator account, and run "Enable-PSRemoting" or "winrm quickconfig" to enable winrm.

Best Regards,

Lee

Just do it.


Friday, December 28, 2018 1:22 PM


Friday, December 28, 2018 1:23 PM

Hello ,

As per your suggestion I have enabled PSRemoting on the destination server but now I am getting below error

New-PSSession : [xx.xxx.xxx.xxx] Connecting to remote server xx.xxx.xxx.xxx failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a
firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:2 char:12

  • $Session = New-PSSession -ComputerName "xx.xxx.xxx.xxx" -Credential " ...
    +            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
        + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
    Copy-Item : Cannot validate argument on parameter 'ToSession'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
    At line:3 char:80
  • ... st.log" -Destination "C:\Folder001_Copy\ -ToSession $Session -Recurs ...
    +                                                          ~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.CopyItemCommand

Friday, December 28, 2018 1:46 PM

No.  You must enable remoting ON the remote server and not TO the remote server.

\(ツ)_/


Monday, December 31, 2018 11:16 AM

Hello ,

It was a typo, I have enabled remoting on the destination server but still I am not able to upload files



Below is my error:


Monday, December 31, 2018 11:24 AM

Please do not post images.  Post code and errors using the code posting tool.  You must post the code you used to get the error.

With standard settings you need to use the computer NetBIOS name and not the IP.  This is what "Computer name not found" is telling you.

\(ツ)_/


Monday, December 31, 2018 11:29 AM

Thanks for the response.

Code for Enabling Remoting on the destination server

PS C:\Users\Administrator> Enable-PSRemoting -force
WinRM is already set up to receive requests on this computer.
WinRM is already set up for remote management on this computer.
PS C:\Users\Administrator>

Error :

PS C:\WINDOWS\system32>
>> $Session = New-PSSession -ComputerName "xx.xxx.xxx.xxx" -Credential "Administrator"
New-PSSession : [xx.xxx.xxx.xxx] Connecting to remote server xx.xxx.xxx.xxx failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a
firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the
about_Remote_Troubleshooting Help topic.
At line:2 char:12
+ $Session = New-PSSession -ComputerName "xxx.xxx.xxx.xxx" -Credential " ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
PS C:\WINDOWS\system32>

Monday, December 31, 2018 11:32 AM

Ok Let me try with the netbios name, I will update you 


Monday, December 31, 2018 1:51 PM

Hello,

I think you need to trust the remote host 

On the source server, Trust the remote server  

Set-Item WSMan:\localhost\Client\TrustedHosts -Value remote_server

On the remote host trust the source server 

Set-Item WSMan:\localhost\Client\TrustedHosts -Value source_server

Monday, December 31, 2018 1:59 PM

By default, in a domain, all hosts are trusted. It is much safer to check this first.

PS > Get-Item  WSMan:\localhost\Client\TrustedHosts

   WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Client

Type            Name                           SourceOfValue   Value
                                          
System.String   TrustedHosts                                   *
PS >

Notice this is set to a wildcard.  Group Policy may be overriding the setting.  If GP is setting this it cannot be changed locally.

If the client is not trusted or does not trust the server the error will reflect this.

The first test that should be run is:

Test-WSMan  remotepc

Until this works no other tests will be useful.

\(ツ)_/


Monday, December 31, 2018 3:35 PM

I might be totally off-topic, but what about invalid SPN records?


Monday, December 31, 2018 3:52 PM

I might be totally off-topic, but what about invalid SPN records?

First run the test.  If the name is  not resolving or the firewall is not open then SPN records are not the first issue.

The SPN records are created when the system is enabled.  Again - if done via a GPO then the GPO needs to be checked.

\(ツ)_/


Tuesday, January 1, 2019 10:58 AM

 One thing I would like to add to my question that I am trying to copy folder from my source computer (In lan) to AWS remote server over the internet. Are we on the right path using these solution ?


Tuesday, January 1, 2019 11:07 AM

 One thing I would like to add to my question that I am trying to copy folder from my source computer (In lan) to AWS remote server over the internet. Are we on the right path using these solution ?

Please contact AWS for assistance with access to servers on AWS.

\(ツ)_/


Tuesday, January 1, 2019 1:20 PM

Thank you for the response. will it work if I try to copy folder from my local system (in LAN) to other remote server over the internet ?


Tuesday, January 1, 2019 1:24 PM

Thank you for the response. will it work if I try to copy folder from my local system (in LAN) to other remote server over the internet ?

How would we know the answer to that?  You need to work with the owner/vendor of the server to determine if remoting is available and how it is implemented.

\(ツ)_/


Tuesday, January 1, 2019 1:28 PM

Also note that, by default, Windows does not allow remoting over public networks.  This is true of workgroups and of most domains because the firewall is blocking outbound connections.  The vendor of your cloud service can help you understand how to implement this for their systems.'

\(ツ)_/


Tuesday, January 1, 2019 2:35 PM

Thank you the response ,really appreciate your quick response .

We will contact our cloud service provider to resolve this .

Thank you