在 PowerShell 中如何将文件从远程 PSsession 复制到另一个 Windows 服务器 [英] In PowerShell how to copy files from a Remote PSsession to another Windows server

查看:44
本文介绍了在 PowerShell 中如何将文件从远程 PSsession 复制到另一个 Windows 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个文件夹从一个远程服务器复制到一个 PSSession 中的另一个服务器,它给出了诸如访问被拒绝之类的错误.我对两台服务器都有管理员权限.如果我在没有 PSSession 的情况下尝试它,它会起作用.

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.

在远程服务器A

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>

在远程服务器B中

    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>

推荐答案

您正面临双跳"问题.在 SQL 计算机上运行这个

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

Enable-WSManCredSSP -Role Server 

并在服务器 B 上运行它

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)

希望这会有所帮助.

如果您在阅读此答案时打喷嚏,请保佑您的脸.

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

这篇关于在 PowerShell 中如何将文件从远程 PSsession 复制到另一个 Windows 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆