小编sar*_*dok的帖子

远程命令中的最大数据大小

我的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 …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-remoting

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1

powershell-remoting ×1