微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在powershell脚本中访问远程计算机?

如何解决如何在powershell脚本中访问远程计算机?

我正在尝试使用 powershell 脚本将文件从本地计算机复制到远程计算机。

我的脚本:

$Session = New-PSSession -ComputerName "\\10.10.X.X" -Credential "username\password"
copy-Item "D:\Test.txt" -Destination "D:\Self Study\" -ToSession $Session

我得到以下错误

New-PSSession : One or more computer names are not valid. If you are trying to pass a URI,use the -ConnectionUri
parameter,or pass URI objects instead of strings.
At D:\PS_Test_script.ps1:1 char:12
+ $Session = New-PSSession -ComputerName "\\10.10.17.162" -Credential " ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (System.String[]:String[]) [New-PSSession],ArgumentException
    + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.NewPSSessionCommand

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 D:\PS_Test_script.ps1:2 char:66
+ ... -Item "D:\Test.txt" -Destination "D:\Self Study\" -ToSession $Session
+                                                                  ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [copy-Item],ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterargumentValidationError,Microsoft.PowerShell.Commands.copyitemcommand

如何使用计算机名访问远程计算机?这里使用IP地址有问题吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。