【发布时间】:2017-04-11 22:29:40
【问题描述】:
我正在尝试通过Copy-Item cmdlet 的-FromSession 参数从远程会话复制一些日志文件。在呼叫机器上,我安装了 PS 版本 5。运行脚本时出现以下错误:
Copy-Item : A parameter cannot be found that matches parameter name 'FromSession'.
当我在源计算机上调用 $PSVersionTable 时,我得到以下输出:
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
我还检查了会话状态,它已打开:
$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版本。
有什么提示吗?
【问题讨论】:
标签: powershell powershell-4.0 powershell-5.0