Archivo de salida -out file- en powershell
Tengo el siguiente código en powershell, el cual funciona sin problema alguno: el archivo que me genera pesa por ejemplo 250kb, pero debe de ser de 700kb, cómo puedo hacer para que la captura que hago mediante el out-file quede completo, es decir, no me detenga la captura. Gracias
Function conexion
{ Param (
[Parameter(ValueFromPipeline=$true)]
[String[]]$Commands = @("username","password","disable clipaging","sh config"),
[string]$RemoteHost = "HostnameOrIPAddress",
[string]$Port = "23",
[int]$WaitTime = 1000,
[string]$OutputPath = "\\server\share\ciscoswitch.txt"
)
$Socket = New-Object System.Net.Sockets.TcpClient($RemoteHost, $Port)
If ($Socket)
{ $Stream = $Socket.GetStream()
$Writer = New-Object System.IO.StreamWriter($Stream)
$Buffer = New-Object System.Byte[] 1024
$Encoding = New-Object System.Text.AsciiEncoding
ForEach ($Command in $Commands)
{ $Writer.WriteLine($Command)
$Writer.Flush()
Start-Sleep -Milliseconds $WaitTime
}
Start-Sleep -Milliseconds ($WaitTime * 4)
$Result = ""
While($Stream.DataAvailable)
{ $Read = $Stream.Read($Buffer,0, 1024)
$Result += ($Encoding.GetString($Buffer,0, $Read))
}
}
Else
{ $Result = "Unable to connect to host: $($RemoteHost):$Port"
}
$Result | Out-File $OutputPath
}