I got a script that is supposed to move a file on the FTP server and also copy it to a local folder. The copy works, but moving the file only creates it in the remote folder on the FTP and leaves the file in the original place. This only happens with the script is ran by a scheduled task on Windows Server 2012 R2. When I run the script manually it works like it's supposed to. The exit code for the script is 0x1.
#Load WinSCP .NET assembly
Add-Type -Path 'WinSCPnet.dll'
#Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = $Server
$sessionOptions.UserName = $Username
$sessionOptions.SecurePassword = ConvertTo-SecureString $EncryptedPW
$sessionOptions.SshHostKeyFingerprint = $SSHKey
$session = New-Object WinSCP.Session
$session.SessionLogPath = $sessionLogPath
# Connect to FTP server
# Copy files
# Move files
I've attached the log file.