Unable to use variables in .SessionLogPath ?

Advertisement

sc554
Joined:
Posts:
1

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?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
42,328
Location:
Prague, Czechia

Re: Unable to use variables in .SessionLogPath ?

It seems that the $LogPath = "..\Logs", and the ..\Logs is probably not a valid path. Use "C:\test", like you do in your "C:\test\WinSCP.log" test.

Reply with quote

Advertisement

You can post new topics in this forum