powershell - Copy-Item:找不到与参数名称 'FromSession'匹配的参数

标签 powershell powershell-v5.1

当我尝试将文件从远程计算机复制到本地计算机时,出现错误:

Copy-Item : A parameter cannot be found that matches parameter name 'FromSession'.


我将文件复制到同一驱动器,并且两台计算机中都存在该驱动器和路径。

这是预期的行为吗?
$sessions = New-PSSession -ComputerName "xxxxxx"
$sessions | ForEach-Object { Copy-Item -FromSession $_ -Path c:\Test2\\*.txt -Destination C:\Test2 }

最佳答案

这似乎是意外行为或意外启动条件。在我的环境中测试类似的东西效果很好。我的建议有两个:

我会对正在运行的计算机列表进行类似的操作,以确认它们是否在5.1版上

Invoke-command -ComputerName $ComputerList {$PSversionTable.Psversion}

除此之外,如果该行为继续存在,我不确定是否可以解决该问题,但是根据您要执行的操作,在PSsessions之外解决该问题似乎是可行的,除非您使用PSSessions来访问在标准Shell中没有的一些cmdlet或凭据。它可能看起来像这样
Copy-Item -path "\\$Computername\C$\Test2\*.txt" -destination "C:\test2"

关于powershell - Copy-Item:找不到与参数名称 'FromSession'匹配的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52880307/

相关文章:

c# - 从 C# 应用程序运行 PowerShell 脚本

powershell - 确定是否使用 CN(通过 powershell 2.0)安装了证书?

powershell 更新帮助失败

powershell - 无法将 "-persist"添加到 New-PSDrive - 出现错误 "network resource type is not correct"

powershell - 写入信息未显示在由 Start-Transcript 转录的文件中

Powershell v5.1 Invoke-RestMethod 并绕过代理

powershell - Get-Printer powershell cmdlet 返回的信息的来源是什么?

azure - 使用 Azure Powershell 操作 Azure Api 管理时出现 PessimisticConcurrencyConflict 错误

PowerShell - 过滤唯一值