找不到 Powershell 版本 5 Copy-Item -FromSession [英] Powershell version 5 Copy-Item -FromSession cannot be found
问题描述
我正在尝试通过 Copy-Item
cmdlet 的 -FromSession
参数从远程会话复制一些日志文件.在主叫机上,我安装了 PS 版本 5.运行脚本时出现以下错误:
I'm trying to copy some log files from a remote session via the -FromSession
paramter of the Copy-Item
cmdlet. On the calling machine I've PS version 5 installed. When running the script I get following error:
Copy-Item : A parameter cannot be found that matches parameter name 'FromSession'.
当我在源机器上调用 $PSVersionTable
时,我得到以下输出:
When I'm calling $PSVersionTable
on the source machine I get following output:
PSVersion 5.0.10586.672
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.672
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
我还检查了会话状态,它是打开的:
I also check the session state, it is opened:
$session | select State
State
-----
Opened
脚本:
$globalTargets = @("machine1.domain", "machine2.domain")
function Copy-LogsFromRemotes {
param (
[Parameter(Mandatory=$true)]
$Destination
)
$password = "xxxxx" | ConvertTo-SecureString -AsPlainText -Force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "domain\user",$password
foreach ($target in $globalTargets) {
$session = New-PSSession -ComputerName $target -Credential $credentials
if (!(Test-Path $Destination)){
New-Item -Path $Destination -ItemType Directory
}
$copyDestination = ("{0}\{1}" -f $Destination, $session.ComputerName)
if (!(Test-Path $copyDestination)){
New-Item -Path $copyDestination -ItemType Directory
}
Invoke-Command -Session $session -ScriptBlock { Test-Path "D:\Logs"}
Copy-Item -LiteralPath "D:\Logs" -Destination $copyDestination -Verbose -FromSession $session
Remove-PSSession -Session $session
}
}
目标机器上是否还需要 PS 版本 5?实际上目标上安装了PS版本.
Do I also need PS version 5 on the target machine? Actually PS version is installed on the target.
有什么提示吗?
推荐答案
当您尝试从不同驱动器复制文件或将文件复制到不同驱动器时,您可能会遇到此 PowerShell 5.0 错误.如果其他系统上不存在该驱动器,则会发生此错误.
You can come across this PowerShell 5.0 bug when you try to copy files from or to different drives. If the drive does not exist on the other system, this error occurs.
作为一种解决方法,您可以:
As a workaround you could:
- 将文件复制到 C:-驱动器(或其他通用驱动器)上的临时文件夹
- 复制这些文件到/从远程机器
- 将文件移动到最终目的地
这篇关于找不到 Powershell 版本 5 Copy-Item -FromSession的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!