How to get the results of LS into a variable

Advertisement

AssistanceRequested
Guest

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?

Reply with quote

Advertisement

OP
Guest

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?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum