-1

I'm trying to create a simple script which run a command and send the output to a variable. this is the script:

$output = &"<Path to PLINK>\PLINK.exe" -ssh <username>@<IP Address> -pw <password> "my command"

the thing is the command im running is like "top" in linux - a task manager which won't quit until enter is being pressed.

how can i take the CLI output from that situation without touching my keyboard?

i wrote an automation with opening cmd and sending "keys" function inorder to get what i want but i cannot get the output from the CLI by doing so. (also i dont beleive its the right way.)

Thanks in advance.

Current Redemption
  • 169
  • 1
  • 1
  • 11

2 Answers2

-1

As I saw in the following page: Run As Admin

using the following code will run the programm PLINK.EXE for you.

$Username = 'Username'
$Password = 'Password'
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($Username,$SecurePassword)

Start-Process powershell.exe  -Credential $Credential -NoNewWindow -ArgumentList "(Start-Process -FilePath '\\some\path\app.exe' -ArgumentList  '/q).ExitCode"
Kamel
  • 47
  • 4
-1

I solved my issue by installing POSH-SSH module for Powershell.

Current Redemption
  • 169
  • 1
  • 1
  • 11