2012-11-26 128 views
2

我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 

這裏描述的完全複製功能的文件發送到多個客戶定製的會話中大於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會話對象。

就是做這個配置在遠程機器或其他地方需要它?什麼導致這個錯誤?

感謝。

回答

11

您需要創建一個新的PSSessionConfiguration在遠程計算機(這不使用默認的):

Register-PSSessionConfiguration -Name DataNoLimits #or the name you like. 

然後配置你想要的參數(在這種情況下MaximumReceivedDataSizePerCommandMBMaximumReceivedObjectSizeMB):

$Session = New-PSSession -ComputerName MyRemoteComp -ConfigurationName DataNoLimits 
Set-PSSessionConfiguration -Name DataNoLimits ` 
-MaximumReceivedDataSizePerCommandMB 500 -MaximumReceivedObjectSizeMB 500 

然後與PSSessionConfiguration你需要創建新的會話0

在您的本地計算機中。

在使用從posh.org發送,文件這樣我複製〜80MB大小的文件。 更大的尺寸返回我outofmemory異常。

更多這here.

+0

感謝回覆上。增加了具有適當值的新ps會話配置,但也沒有工作。我在本地主機上設置它,設置值後執行enable-psremoting,restart-service winrm。也嘗試過32bt/64bit的PowerShell實例,沒有幫助。 – sardok

+0

@sardok您是否嘗試將$ null更改爲文件大小的最大值? –

+0

是的,我沒有,但沒有工作,其實你的建議是我的做法據我所知幾乎相同。 – sardok