maximum data size in a remote command
powershell, powershell-remoting
Solution
You need to create a new `PSSessionConfiguration` (this to not use the default one) in your remote computer:
Register-PSSessionConfiguration -Name DataNoLimits #or the name you like.
Then configuring the parameter you want (in this case `MaximumReceivedDataSizePerCommandMB` and `MaximumReceivedObjectSizeMB`):
Set-PSSessionConfiguration -Name DataNoLimits `
-MaximumReceivedDataSizePerCommandMB 500 -MaximumReceivedObjectSizeMB 500
Then create the new session with the `PSSessionConfiguration` you need:
$Session = New-PSSession -ComputerName MyRemoteComp -ConfigurationName DataNoLimits
in your local Computer.
In this way using the Send-File from posh.org I copy a file of ~80MB size. Bigger size return me outofmemory exception.
Problem
my powershell script sends a file to several clients within customised session using following code (code is shortened) ``` 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 ``` The full copy function is described here: http://poshcode.org/2216 The problem arises with a file larger than 52MB. it fails with following error: ``` 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 ``` 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. Is it required to do this configuration on remote machine or somewhere else? what is causing this error? thanks.