In PowerShell how to copy files from a Remote PSsession to another Windows server

我的未来我决定 提交于 2019-12-04 04:21:31

问题


I am trying to copy a folder from one remote server to another inside a PSSession, it's giving errors like access is denied. I have admin privileges to both of the servers. If I try it without PSSession it works.

In remote serverA

PS C:\Users\Automation\Documents> [System.Net.Dns]::GetHostName()
sql
PS C:\Users\Automation\Documents> Copy-Item -Path .\abc.csv -Destination "\\jump\c$"
PS C:\Users\Automation\Documents>

In remote serverB

    PS C:\Users\Automation\Documents\sample\SQL Final Scripts> Copy-Item -Path ".\SQL_queries.csv" -Destination "\\sql\c$\"
    PS C:\Users\Automation\Documents\sample\SQL Final Scripts> Enter-PSSession -ComputerName sql  -Credential "automation@lab"

    [sql]: PS C:\Users\Automation\Documents> Copy-Item -Path ".\SQL_queries.csv" -Destination "\\jump\c$\"


Copy-Item : Access to the path '\\jump\c$\' is denied.
        + CategoryInfo          : PermissionDenied: (C:\Users\Automa...SQL_queries.csv:FileInfo) [Copy-Item], Unauthorized
       AccessException
        + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand


    [sql]: PS C:\Users\Automation\Documents>

回答1:


You are facing the "Double Hop" problem. Run this on the SQL computer

Enable-WSManCredSSP -Role Server 

and run this on Server B

Enable-WSManCred -Role Client -DelegateComputer * 

then when you enter the remote session do

Enter-PSSession -ComputerName sql -Authentication Credssp -Credential (Get-Credential)

Hope this helps.

If you sneezed during reading this answer, Bless your face.




回答2:


In case you would like to read more about the "Double Hop" issue, refer to this article: Multi-Hop Support in WinRM




回答3:


I believe you are facing the "double hop" problem, which is solved by using CredSSP



来源:https://stackoverflow.com/questions/15501241/in-powershell-how-to-copy-files-from-a-remote-pssession-to-another-windows-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!