Unable to log output from powershell script.
Hi all!
I'm really new to powershell, and need some help figuring out why this script fails.
Here's the script:
try
{
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
# Setup session options
$SessionOptions.DisableVersionCheck
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "***"
$sessionOptions.UserName = "***"
$sessionOptions.Password = "***"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 ***"
$session.SessionLogPath = "\\***\Log\Uploaded.log"
$session = New-Object WinSCP.Session
try
{
$session.ExecutablePath = "D:\Program Files (x86)\WinSCP\winscp.exe"
# Connect
$session.Open($sessionOptions)
$localPath = "\\***\testwebexp*.txt"
$remotePath = "/**/out/"
$backupPath = "\\***exp\processed\"
# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
The script works well when i remove the line :
$session.SessionLogPath = "\\linux1\v\prod\dataexch\no2\vismaservicessere\exp\Log\Uploaded.log"
But when i try to run it with the løine it fails with this error:
The property 'SessionLogPath' cannot be found on this object. Verify that the property exists and can be set.
These's somewhere where i need to include this, but im do dumt to figure it out myself.
Could anyone please give me a helping hand ?
I'm really new to powershell, and need some help figuring out why this script fails.
Here's the script:
try
{
# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("WinSCPnet.dll") | Out-Null
# Setup session options
$SessionOptions.DisableVersionCheck
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "***"
$sessionOptions.UserName = "***"
$sessionOptions.Password = "***"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 ***"
$session.SessionLogPath = "\\***\Log\Uploaded.log"
$session = New-Object WinSCP.Session
try
{
$session.ExecutablePath = "D:\Program Files (x86)\WinSCP\winscp.exe"
# Connect
$session.Open($sessionOptions)
$localPath = "\\***\testwebexp*.txt"
$remotePath = "/**/out/"
$backupPath = "\\***exp\processed\"
# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath)
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host ("Upload of {0} succeeded, moving to backup" -f
$transfer.FileName)
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host ("Upload of {0} failed: {1}" -f
$transfer.FileName, $transfer.Error.Message)
}
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch [Exception]
{
Write-Host $_.Exception.Message
exit 1
}
The script works well when i remove the line :
$session.SessionLogPath = "\\linux1\v\prod\dataexch\no2\vismaservicessere\exp\Log\Uploaded.log"
But when i try to run it with the løine it fails with this error:
The property 'SessionLogPath' cannot be found on this object. Verify that the property exists and can be set.
These's somewhere where i need to include this, but im do dumt to figure it out myself.
Could anyone please give me a helping hand ?