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地址是错误的吗?
解决方案
推荐阅读
- permissions - Keycloak中细粒度权限中的“管理成员”权限是否允许创建新用户?
- c# - 如何在客户端代码中拦截来自 WCF 服务的 HTTP 响应代码
- javascript - Kotlin 是否支持 Javascript、Swift 或 Dart 等匿名对象?
- php - 预匹配检查是否在场
- javascript - 使用“switch”语句显示星期几。(问题)
- python - 打印每个单词的第一个和最后一个字母的代码
- vb.net - 将数据从 Ms-access 传递到水晶报告到详细信息部分 vb.net
- python - 将列表拆分为较小的大小相等的列表,保持“中间值”?
- spring-boot - 是否可以在 Spring Data Rest 中通过关联进行搜索?
- reactjs - 托管在 AWS S3 API 请求上的 React 应用程序失败