Home > Enterprise >  Is there a way to pass an echo argument with start-process in powershell?
Is there a way to pass an echo argument with start-process in powershell?

Time:12-01

I'm trying to automatically connect an Anydesk Session in Powershell.

According to their CLI documentation, you can pass password with echo.

Right now, I'm starting the process like this, since I need the process ID afterward.

$app = Start-Process $config.anydesk_path -ArgumentList @($config.ip_addresses[$i], "--plain") -passthr

I've tried appending the password to the Argument List like this

$app = Start-Process $config.anydesk_path -ArgumentList @($config.connect_pw, $config.ip_addresses[$i], "--plain", "--with-password") -passthru 

but that doesn't seem to enter the password.

Is there a way to send the password with Start-Process?

Thanks.

CodePudding user response:

Sadly, Start-Process can only accept input from a file (See -RedirectStandardInput parameter).

You can use .NET Framework Process class directly:

$AnyDesk = New-Object System.Diagnostics.Process

$AnyDesk.StartInfo.FileName = $config.anydesk_path
$AnyDesk.StartInfo.UseShellExecute = $false

# This allows writing to a standard input stream:
$AnyDesk.StartInfo.RedirectStandardInput = $true

$AnyDesk.StartInfo.Arguments = "$($config.ip_addresses[$i]) --plain --with-password"

$AnyDesk.Start()

# Write a password into standard input stream:
$AnyDesk.StandardInput.WriteLine($config.connect_pw)

# Grab a process ID:
$AnyDesk.Id
  • Related