首页 > 解决方案 > 用于将文件从一台服务器复制到另一台服务器的 Powershell 脚本

问题描述

带有凭据的 PowerShell 脚本,用于将文件从一台服务器复制到另一台服务器。

我已经编写了代码,但它不工作。我的代码有什么问题?我得到错误

New-PSSession : myComp1 连接到远程服务器 myComp1 失败并显示以下错误消息:WS-Management 服务无法处理请求。在 myComp1 计算机上的 WSMan: 驱动器中找不到 Microsoft.PowerShell 会话配置。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。

$pw = ConvertTo-SecureString -AsPlainText -Force -String password
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "domain\UserName", $pw
$trgtSession = New-PSSession -ComputerName myComp1 -Credential $creds 
Copy-Item -ToSession $trgtSession -Path "C:\Users\" -Destination "C:\Users\desktop\" -Recurse

预期结果:使用凭据将文件从一台服务器移动到另一台服务器的代码。

标签: powershellpowershell-remoting

解决方案


推荐阅读