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

Follow-up

But that would mean putting the credentials in clear text in the script?
OP

Martin, thanks. I'm not having success that way. I get this error:
 New-Object : The member "Site" was not found for the specified .NET object.

At line:5 char:23
+     $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
+                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.NewObjectCommand
 
Error: Exception calling "Open" with "1" argument(s): "Value cannot be null.
Parameter name: sessionOptions"

I'm guessing it doesn't like this:
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Site = "MySiteName"
}

I have my site defined in the GUI. How do I invoke it as a property of SessionOptions?
AssistanceRequested

How to get the results of LS into a variable

I want to automate the following:

  1. Open my defined site
  2. Run ls—which is a supported command—and have the output from it go to a variable, a file, *anything* that I can then read back into the next step of my PowerShell script.

Automation works fine. I can open my defined site, create directories, upload and download files. I'm guessing ls is working just fine, but there's no obvious way to capture the output.

How can I accomplish this?