我的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)