我想通過Copy-Item
cmdlet的參數-FromSession
參數從遠程會話複製一些日誌文件。在調用機器上,我安裝了PS版本5。運行腳本時,我得到以下錯誤:Powershell版本5複製項目-FromSession無法找到
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版本安裝在目標上。
任何提示?