Corrupt Folder Objects - Script Keeps Stopping on Failure
I did a good read up on the
Log snippet file attached.
$session.add_QueryReceived, but it is not just clicking with me. My PowerShell script to download a bunch of files hits this one corrupt folder item and kills it. I intend to continue past the corrupt folder objects. Something with the .Check()? I tried adding some stuff, but I'm a little confused. Haven't touched PowerShell in a long time. Attached is the code and relevant log snippet.
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Ftp HostName = "xx.xx.com" UserName = "xxxx" Password = $plainPass FtpSecure = [WinSCP.FtpSecure]::Implicit Timeout = New-TimeSpan -Seconds 600 } # Session object $session = New-Object WinSCP.Session # Log Path $session.SessionLogPath = "C:\Users\User1\C1\Documents\ImportExportTeam\Daily_Eligibility_Runs_REPO\Logs\.logs\USHC.log" # Connect $session.add_QueryReceived({ $entry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') | SKIPPED | $($_.Message)" Add-Content -Path $errorLog -Value $entry $_.Continue() }) $session.Open($sessionOptions) # Transfer Options $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.AddRawSettings("ExcludeEmptyDirectories", "1") $transferOptions.AddRawSettings("NewerOnly", "1") ## Paycheck Comparisons--------------- $remotePath = "/1 A CLIENTS/xCompany/Client Folders/" $localPath = "C:\Users\User1\C1\Eligibility Files\xCompany\" # Masking $transferOptions.FileMask = "*Paycheck Comparison*/*.* | *Archive*/; *Opt*/; *Enrollment*/; *Census*/; *Deduction*/; *Actual*/" # Download files $result = $session.GetFiles($remotePath, $localPath, $False, $transferOptions) $result.Check() foreach ($transfer in $result.Transfers) { $entry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') | $($transfer.FileName)" Add-Content -Path $downloadLog -Value $entry }