powershell - 有没有办法在 powershell 中通过 start-process 传递 echo 参数?

标签 powershell

我正在尝试在 Powershell 中自动连接 Anydesk session 。

根据他们的CLI documentation ,您可以使用 echo 传递密码。

现在,我正在开始这样的流程,因为之后我需要流程 ID。

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

我尝试像这样将密码附加到参数列表

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

但是好像没有输入密码。

有没有办法通过 Start-Process 发送密码?

谢谢。

最佳答案

可悲的是,Start-Process只能接受来自文件的输入(请参阅 -RedirectStandardInput 参数)。

您可以使用.NET Framework Process直接上课:

$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

关于powershell - 有没有办法在 powershell 中通过 start-process 传递 echo 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70168825/

相关文章:

powershell - 为什么这个 powershell 代码段会产生额外的空行?

powershell - 初始化将被导出的 powershell 模块变量

azure - 检查 az cli 输出以查看是否返回值

sql-server - 使用powershell在sql server中创建包含记录的表: what's best?

.net - 一元运算符 '--' 后缺少表达式

powershell - Invoke-RestMethod 卡在长时间运行的端点上

powershell - 较短版本的 powershell cmdlet 参数

c# - 如何使用 Windows 和/或 PowerShell 使用的接口(interface)和/或方法创建类库?

powershell - 查找具有特定扩展名的所有文件,按创建时间对它们进行排序并使用新名称复制它们

powershell - 在通过 GUI [powershell] 访问之前无法访问卷影复制