title: maximum data size in a remote command
body: <p>my powershell script sends a file to several clients within customised session using following code (code is shortened)</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The full copy function is described here: <a href="http://poshcode.org/2216" rel="nofollow">http://poshcode.org/2216</a></p>
  
  <p>The problem arises with a file larger than 52MB. it fails with following error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>As you see in the code, i use customised ps session. when i set MaximumReceivedDataSizePerCommand to very low values (like 10kb) it fails with a message which tells maximum is 10kb, so i assume that MaximumReceivedDataSizePerCommand  is applied to ps session object.</p>
  
  <p>Is it required to do this configuration on remote machine or somewhere else? what is causing this error?</p>
  
  <p>thanks.</p>