For those of you wondering what I resorted to as a solution to my “SSH + SCP using PowerShell” posting. I turned to WinSCP. Basically, I just wrote a script that would generate a WinSCP script on the fly and then execute that script within a WinSCP console session. Quick and dirty, but it works! Here is the relevant code:
# Get files to transfer = get-childitem -path “$TMP” -exclude “*.txt”foreach ($Record in $CDPSessions){trap{Continue}# Create SCP Script Filearray]$Script = “option batch on”$Script += “option confirm off”$Script += “lcd $TMP”$Script += “cd $($Record.Path)” $Files | foreach {$Script += ‘put “‘ + $_ + ‘”‘}$Script += “close”$Script += “exit”# Dump script file$Script | out-file -filePath “$TMPscp.txt” -encoding “ASCII”# SCP files to CDP points$Process = [diagnostics.process]::Start(“$Resourceswinscp405.exe”, `”$($Record.Session) /console /script=$TMPscp.txt”)$Process.WaitForExit()
$Files
&{
[
}
}
There are a couple of interesting things in the above code. For one, I’m now using an IDE to write my scripts now. This is a new development for me as I’m old school and always just used the universal IDE named Notepad. In case you’re wondering what IDE I’m using now, it’s the PowerGUI Script Editor (www.powergui.org). The second interesting thing is that I’m using a Diagnostics.Process object to monitor when the WinSCP script has stopped executing. Needed to throw this into the mix because of the way WinSCP handled the script console in relation to the winscp405.exe process that I was starting. Kinda of cool…
On another note I’m going to make a couple of announcements. The first item is older news. The second item is a little new in nature.
- 1) My PowerShell book is now being sold at the Redmond Microsoft Store.
- 2) I’m just putting the finishing touches on a PowerShell course for www.aspetech.com.
Yes, those were shameless plugs, but I’m allowed to do that every once in awhile.




