PowerShell OutputDataReceived not displaying much info
Most of the code is from example code. The code works as far as syncing files from server.
I would like to see what is going on on the console I am running this from. The
In the debug log, I can see every file/folder attempted to sync and I can see the actual sync occurring on the server logs.
I would like to see what is going on on the console I am running this from. The
$logPath
has the info I would like to print on screen. OutputDataReceived
displays text at startup, and then whenever the server times out and attempts reconnect, but no other time.
In the debug log, I can see every file/folder attempted to sync and I can see the actual sync occurring on the server logs.
param ( $localPath = $PSScriptRoot, $remotePath = '/offers/', $logPath = $PSCommandPath.replace('ps1', 'log') ) Add-Type -Path ([IO.Path]::Combine($PSScriptRoot, 'WinSCPnet.dll')) ##################################################################################################################### ### Session.OutputDataReceived event handler ##################################################################################################################### function OutputDataReceived { param($e) Write-Host $e } ##################################################################################################################### ### Session.FileTransferred event handler ##################################################################################################################### function FileTransferred { param($e) write-host $e } # Main script try { $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Ftp HostName = 'site' UserName = 'user' Password = 'pwd' FtpSecure = [WinSCP.FtpSecure]::Explicit TlsHostCertificateFingerprint = 'fingerprint' } $session = New-Object WinSCP.Session try { # event handlers # Will continuously report progress of synchronization $session.add_FileTransferred( { FileTransferred($_) } ) $session.add_OutputDataReceived( { OutputDataReceived($_) } ) $session.DebugLogLevel = -1 $session.SessionLogPath = $logPath # Connect $session.Open($sessionOptions) $synchronizationResult = $session.SynchronizeDirectories( [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $False, $False) # Throw on any error $synchronizationResult.Check() } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }