gpt4 book ai didi

windows - 如何通过 PowerShell 脚本将文件从 Windows 复制到 Ubuntu

转载 作者:行者123 更新时间:2023-12-04 18:28:49 27 4
gpt4 key购买 nike

源是 Windows,目标是 Ubuntu(安装在 VMware 播放器上)。
我在 Windows 中运行以下脚本:

$targetComputerName = "192.168.22.130"
$Username = 'zahid'
$Password = 'Z@hid1212'
$Pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString= $pass
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString

$Session = New-PSSession $targetComputerName -Credential $MySecureCreds
$DestinationPath = "/home/zahid/Downloads"
$Source = 'D:\zahid.txt'

Copy-Item -Path $Source -ToSession $Session -Destination $DestinationPath
$Session | Remove-PSSession
并得到错误:
New-PSSession : [192.168.22.130] Connecting to remote server 192.168.22.130 failed with the following error message : The client cannot connect to the destination 
specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management
service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
At C:\Users\DELL\Desktop\Untitled1.ps1:8 char:12
+ $Session = New-PSSession $targetComputerName -Credential $MySecureCre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CannotConnect,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 C:\Users\DELL\Desktop\Untitled1.ps1:12 char:36
+ Copy-Item -Path $Source -ToSession $Session -Destination $Destination ...
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.CopyItemCommand
我还需要在目的地(这里是 Ubuntu)上设置 winrm 服务吗?我怎样才能做到这一点?

最佳答案

我以前用WinScp使用 PowerShell,或 Posh-SSH .
这两种方法允许您在 Linux 上利用传统的 SSH。
从 PowerShell 6 开始,您可以使用 PowerShell remoting over SSH ,此链接显示您在 Windows 和 Ubuntu 上的设置。

关于windows - 如何通过 PowerShell 脚本将文件从 Windows 复制到 Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68669287/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com