Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7664715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:22:30+00:00 2026-05-31T14:22:30+00:00

I need to write the output of cmd command DIR to powershell variable(array). Is

  • 0

I need to write the output of cmd command DIR to powershell variable(array). Is it possible? I need it because I use cmd scripting in WinSCP (SFTP client) and when I’m connected to sftp server, I can use cmd commands only, not powershell. But I need to get names and size of files that are in the remote directory to check if the transfer was successful. This is my script which connects to sftp and upload some files:

C:\"Program Files"\WinSCP\winscp.com /console /command "option batch abort" "option confirm off" "open sftp://login:password@195.22.89.55" "cd import" "option transfer binary" "put C:\_ZbankyNaOdoslanie\*.gpg" "put C:\_ZbankyNaOdoslanie\*.chk" "close" "exit"

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:22:31+00:00Added an answer on May 31, 2026 at 2:22 pm

    You can invoke this line in PowerShell using the call operator & and assign it’s stdout and/or stderr to a variable.

    Example:

    $output = & "C:\Program Files\WinSCP\winscp.com" /arg1 /arg2
    

    The variable $output will be an array of strings. Each line of output will be an array element.

    More examples:

    • Just stdout: $output = & "C:\Program Files\WinSCP\winscp.com" /arg1 /arg2 2>$null
    • Just stderr: $output = & "C:\Program Files\WinSCP\winscp.com" /arg1 /arg2 1>$null
    • Both: $output = & "C:\Program Files\WinSCP\winscp.com" /arg1 /arg2 2>&1
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a script that will use document.write to produce some output,
I need to write a function to satisfy this input -> output list: 0
I have a Windows Forms application that I need to write to the output
I need to write a program which will write many characters in a output
I need to write a bash script that will take a grepable nmap output
I need to write tests after ETL process and need to format the output
I need my custom team build task to write some output to the build
I am new to perl I need some help to write my output to
I need to write an Objective-C method whose input is an array of strings
I need to write a script that will output data from a PostgreSQL database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.