Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

sc554

Unable to use variables in .SessionLogPath ?

Hello,
I'm pretty new to all this - but am trying to use the .NET assembly within PowerShell to initiate a WinSCP session to download a few files.

I'm trying to use:
$RUNDATETIME = "$RUNDATE" + "_" + "$RUNTIME"

$WinSCPLogFile = "$LogPath\$RUNDATETIME WinSCP.log"
$session.SessionLogPath = $WinSCPLogFile


$RUNDATE and $RUNTIME I specify elsewhere as the date and time - I'm using those elsewhere and they're working fine.

If I specify explicitely:
$session.SessionLogPath = "C:\test\WinSCP.log"

It works fine. But as soon as I add a variable in there, I get errors on running:
Exception calling "Open" with "1" argument(s): "Error occurred during logging. It's been

turned off.
Can't open log file '..\Logs\2025-08-19_13-27 WinSCP.log'.
System Error.  Code: 2.
The system cannot find the file specified"


Can anyone assist?