我的 powershell 脚本使用以下代码将文件发送到自定义会话中的多个客户端(代码已缩短)
function DoCopyFile
{
param(
[Parameter(Mandatory=$true)] $RemoteHost,
[Parameter(Mandatory=$true)] $SrcPath,
[Parameter(Mandatory=$true)] $DstPath,
[Parameter(Mandatory=$true)] $Session)
.
.
.
$Chunks | Invoke-Command -Session $Session -ScriptBlock { `
param($Dest, $Length)
$DestBytes = new-object byte[] $Length
$Pos = 0
foreach ($Chunk in $input) {
[GC]::Collect()
[Array]::Copy($Chunk, 0, $DestBytes, $Pos, $Chunk.Length)
$Pos += $Chunk.Length
}
[IO.File]::WriteAllBytes($Dest, $DestBytes)
[GC]::Collect()
} -ArgumentList $DstPath, $SrcBytes.Length
.
.
.
}
$Pwd = ConvertTo-SecureString $Node.Auth.Password -asplaintext -force
$Cred = new-object -typename System.Management.Automation.PSCredential -ArgumentList ("{0}\{1}" -f $Name, $Node.Auth.Username),$Pwd
$Sopts = New-PSSessionOption -MaximumReceivedDataSizePerCommand 99000000
$Session = New-PSSession -ComputerName $Name -Credential $Cred -SessionOption $Sopts
DoCopyFile $Name ("{0}\{1}" -f $Node.Installer.ResourceDir, $Driver.Name) $Dest $Session
完整的复制功能在这里描述:http: //poshcode.org/2216
大于 52MB 的文件会出现问题。它失败并出现以下错误:
Sending data to a remote command failed with the following error message: The total data received from the remote
client exceeded allowed maximum. Allowed maximum is 52428800. For more information, see the
about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OperationStopped: (CLI-002:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName : CLI-002
正如您在代码中看到的,我使用自定义的 ps 会话。当我将 MaximumReceivedDataSizePerCommand 设置为非常低的值(如 10kb)时,它会失败并显示一条消息,告诉最大值为 10kb,所以我假设 MaximumReceivedDataSizePerCommand 应用于 ps 会话对象。
是否需要在远程机器或其他地方进行此配置?是什么导致了这个错误?
谢谢。