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

martin

Thanks for sharing this!
LordRegent

Here's a PowerShell script that can be run via Task Scheduler to set a WinSCP session's Local Startup Directory to reference the current year and month. It's equally easy to run this once a month or several times a day, using the Triggers settings in Task Scheduler.

$newPath="D:\outgoing & Incoming Files\xyz\xyz SETTLEMENT FILES\$(Get-Date -format "yyyy\\MMM")"

$regValue=[uri]::EscapeDataString($newPath)
Set-ItemProperty -Path 'HKCU:\\Software\Martin Prikryl\WinSCP 2\Sessions\[email protected]\' -Name LocalDirectory -Type String -Value $regValue


You should Google for a recent guide to the full list of tokens allowed by the "format" parameter; some examples are at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date, but beware: significant omissions from that list are "MMM" for the short Month Name and "ddd" for the short Day Name (for those that know them, "format" uses the list M$ popularized with VB and their other Scripting products.)

However, if you're more comfortable with the Unix date formatting tokens, use the "uFormat" parameter instead; see https://ss64.com/bash/date.html#format for details on that list of tokens.

The code is broken up into several commands to enhance understanding and simplify maintenance, but it's technically possible to make this into a one-liner.